tglman / persy
Showing 2 of 2 files from the diff.
Newly tracked file
src/transaction.rs changed.
Newly tracked file
src/lib.rs changed.

@@ -422,6 +422,35 @@
Loading
422 422
        Ok(ValueIter::from(entry))
423 423
    }
424 424
425 +
    /// Get one value or none from a key considering changes in transaction.
426 +
    ///
427 +
    /// # Example
428 +
    ///
429 +
    /// ```rust
430 +
    /// # use persy::{OpenOptions, ValueMode};
431 +
    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
432 +
    /// # let persy = OpenOptions::new().memory()?;
433 +
    /// # let mut tx = persy.begin()?;
434 +
    /// # tx.create_index::<u8,u8>("my_new_index", ValueMode::Cluster)?;
435 +
    /// tx.put::<u8,u8>("my_new_index",10,10)?;
436 +
    /// if let Some(value) =  tx.one::<u8,u8>("my_new_index",&10)?{
437 +
    ///  //...
438 +
    /// }
439 +
    /// # tx.prepare()?.commit()?;
440 +
    /// # Ok(())
441 +
    /// # }
442 +
    /// ```
443 +
    pub fn one<K, V>(&mut self, index_name: &str, k: &K) -> Result<Option<V>, PE<IndexChangeError>>
444 +
    where
445 +
        K: IndexType,
446 +
        V: IndexType,
447 +
    {
448 +
        for v in self.get(index_name, k)? {
449 +
          return Ok(Some(v));
450 +
        }
451 +
        Ok(None)
452 +
    }
453 +
425 454
    /// Browse a range of keys and values from an index including the transaction changes
426 455
    ///
427 456
    /// # Example

@@ -503,6 +503,36 @@
Loading
503 503
        Ok(ValueIter::from(self.persy_impl.get::<K, V>(index_id, k)?))
504 504
    }
505 505
506 +
    /// Get one value or none from a key considering changes in transaction.
507 +
    ///
508 +
    /// # Example
509 +
    ///
510 +
    /// ```rust
511 +
    /// # use persy::{ValueMode, OpenOptions};
512 +
    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
513 +
    /// # let persy = OpenOptions::new().memory()?;
514 +
    /// # let mut tx = persy.begin()?;
515 +
    /// # tx.create_index::<u8,u8>("my_new_index", ValueMode::Cluster)?;
516 +
    /// # tx.put::<u8,u8>("my_new_index",10,10)?;
517 +
    /// # let prepared = tx.prepare()?;
518 +
    /// # prepared.commit()?;
519 +
    /// if let Some(value) = persy.one::<u8,u8>("my_new_index",&10)? {
520 +
    ///     //...
521 +
    /// }
522 +
    /// # Ok(())
523 +
    /// # }
524 +
    /// ```
525 +
    pub fn one<K, V>(&self, index_name: &str, k: &K) -> Result<Option<V>, PE<IndexOpsError>>
526 +
    where
527 +
        K: IndexType,
528 +
        V: IndexType,
529 +
    {
530 +
        for v in self.get(index_name, k)? {
531 +
          return Ok(Some(v));
532 +
        }
533 +
        Ok(None)
534 +
    }
535 +
506 536
    /// Browse a range of keys and values from and index.
507 537
    ///
508 538
    /// # Example
Files Coverage
src 91.81%
tests 98.91%
Project Totals (37 files) 93.11%
Notifications are pending CI completion. Waiting for GitLab's status webhook to queue notifications. Push notifications now.
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: 80%
6
        threshold: 1.0%
7
    patch: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading