Struct jammdb::Cursor[][src]

pub struct Cursor<'a> { /* fields omitted */ }

An iterator over a bucket

A cursor is created by using the cursor function on a [Bucket]. It's primary purpose is to be an Iterator over the bucket's Data. By default, a newly created cursor will start at the first element in the bucket (sorted by key), but you can use the seek method to move the cursor to a certain key / prefix before beginning to iterate.

Note that if the key you seek to exists, the cursor will begin to iterate after the

Examples

use jammdb::{DB, Data};

let db = DB::open("my.db")?;
let mut tx = db.tx(false)?;
let bucket = tx.get_bucket("my-bucket")?;

// create a cursor and use it to iterate over the entire bucket
for data in bucket.cursor() {
    match &*data {
        Data::Bucket(b) => println!("found a bucket with the name {:?}", b.name()),
        Data::KeyValue(kv) => println!("found a kv pair {:?} {:?}", kv.key(), kv.value()),
    }
}

let mut cursor = bucket.cursor();
// seek to the key "f"
// if it doesn't exist, it will start at the position wh
cursor.seek("f");
//
for data in cursor {
}

Implementations

impl<'a> Cursor<'a>[src]

pub fn seek<T: AsRef<[u8]>>(&mut self, key: T) -> bool[src]

Moves the cursor to the given key. If the key does not exist, the cursor stops "just before" where the key would be.

Returns whether or not the key exists in the bucket.

pub fn current(&self) -> Option<Data>[src]

Returns the data at the cursor's current position. You can use this to get data after doing a seek.

Trait Implementations

impl<'a> Iterator for Cursor<'a>[src]

type Item = Ref<'a, Data>

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Cursor<'a>[src]

impl<'a> !Send for Cursor<'a>[src]

impl<'a> !Sync for Cursor<'a>[src]

impl<'a> Unpin for Cursor<'a>[src]

impl<'a> !UnwindSafe for Cursor<'a>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.