Struct Cursor

Source
pub struct Cursor<'a, B: Deref<Target = Bucket> + 'a> { /* private fields */ }
Expand description

Cursor represents an iterator that can traverse over all key/value pairs in a bucket in sorted order. Cursors see nested buckets with value == None. Cursors can be obtained from a transaction and are valid as long as the transaction is open.

Keys and values returned from the cursor are only valid for the life of the transaction.

Changing data while traversing with a cursor may cause it to be invalidated and return unexpected keys and/or values. You must reposition your cursor after mutating data.

Implementations§

Source§

impl<'a, B: Deref<Target = Bucket> + 'a> Cursor<'a, B>

Source

pub fn first(&self) -> Result<CursorItem<'a>, Error>

Moves the cursor to the first item in the bucket and returns its key and value. If the bucket is empty then a nil key and value are returned. The returned key and value are only valid for the life of the transaction.

Source

pub fn last(&self) -> Result<CursorItem<'a>, Error>

Moves the cursor to the last item in the bucket and returns its key and value. If the bucket is empty then a nil key and value are returned. The returned key and value are only valid for the life of the transaction.

Source

pub fn next(&self) -> Result<CursorItem<'a>, Error>

Moves the cursor to the next item in the bucket and returns its key and value. If the cursor is at the end of the bucket then a nil key and value are returned.

The returned key and value are only valid for the life of the transaction.

Source

pub fn prev(&self) -> Result<CursorItem<'a>, Error>

Moves the cursor to the previous item in the bucket and returns its key and value. If the cursor is at the beginning of the bucket then a nil key and value are returned. The returned key and value are only valid for the life of the transaction.

Source

pub fn seek(&self, seek: &[u8]) -> Result<CursorItem<'a>, Error>

Moves the cursor to a given key and returns it. If the key does not exist then the next key is used. If no keys follow, a nil key is returned.

The returned key and value are only valid for the life of the transaction.

Source

pub fn delete(&mut self) -> Result<(), Error>

Removes the current key/value under the cursor from the bucket. Delete fails if current key/value is a bucket or if the transaction is not writable.

Auto Trait Implementations§

§

impl<'a, B> !Freeze for Cursor<'a, B>

§

impl<'a, B> !RefUnwindSafe for Cursor<'a, B>

§

impl<'a, B> !Send for Cursor<'a, B>

§

impl<'a, B> !Sync for Cursor<'a, B>

§

impl<'a, B> Unpin for Cursor<'a, B>
where B: Unpin,

§

impl<'a, B> !UnwindSafe for Cursor<'a, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.