Skip to main content

Cursor

Struct Cursor 

Source
pub struct Cursor { /* private fields */ }
Expand description

A database cursor for iterating over records.

Cursors are used for operating on collections of records, for iterating over a database, and for saving handles to individual records so they can be modified after reading.

§Example

use noxu_db::{Database, DatabaseEntry, Get};

let mut cursor = db.open_cursor(None, None)?;
let mut key = DatabaseEntry::new();
let mut data = DatabaseEntry::new();

// Iterate through all records
while cursor.get(&mut key, &mut data, Get::Next, None)? == OperationStatus::Success {
    // Process key and data
}

cursor.close()?;

Implementations§

Source§

impl Cursor

Source

pub fn get( &mut self, key: &mut DatabaseEntry, data: &mut DatabaseEntry, get_type: Get, _lock_mode: Option<LockMode>, ) -> Result<OperationStatus>

Retrieve a record using the cursor.

§Arguments
  • key — search input (for Get::Search / Get::SearchGte) or the output buffer that receives the discovered key (for iteration / range search variants).
  • data — output buffer for the record’s value.
  • get_type — selects the navigation primitive (see Get).
  • lock_mode — reserved for per-operation isolation overrides (e.g., dirty reads inside an otherwise-serializable txn). The current implementation ignores this argument and uses the surrounding transaction’s isolation level (set on crate::transaction_config::TransactionConfig). Per-call read-uncommitted is not yet implemented; pass None for now.
§Returns
  • OperationStatus::Success if the cursor positioned on a record.
  • OperationStatus::NotFound if no record satisfied the request.
§Errors
Source

pub fn put( &mut self, key: &DatabaseEntry, data: &DatabaseEntry, put_type: Put, ) -> Result<OperationStatus>

Store a record using the cursor.

§Arguments
  • key - Key to store
  • data - Data to store
  • put_type - Type of put operation

Store a record using the cursor.

§Arguments
  • key — the record’s key. Empty keys (get_data() returns None or an empty slice) are forwarded to the underlying B-tree which rejects them on writable databases.
  • data — the record’s value.
  • put_type — see Put for the per-mode semantics.
§Returns
  • OperationStatus::Success if the record was inserted or updated.
  • OperationStatus::KeyExists for Put::NoOverwrite / Put::NoDupData when the key (or (key, data) pair under sorted-dup) already exists.
§Errors
Source

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

Delete the record at the current cursor position.

§Returns

OperationStatus::Success if the record was deleted, OperationStatus::NotFound if the cursor is not positioned.

Source

pub fn count(&self) -> Result<u64>

Count the number of records with the same key.

For non-duplicate databases this returns 1 when positioned and 0 otherwise. For sorted-dup databases it returns the number of duplicate values stored under the cursor’s current key.

§Returns

The count of records, or 0 if the cursor is not currently positioned on a record.

§Errors
Source

pub fn close(&mut self) -> Result<()>

Close the cursor.

The cursor handle may not be used again after this call. Any subsequent navigation / mutation operation returns NoxuError::OperationNotAllowed.

close() itself is idempotent: calling it more than once is a no-op and returns Ok(()). This matches BDB-JE’s Cursor.close() contract — calling it more than once is safe.

§Errors

Returns the inner-cursor close error if the underlying CursorImpl::close fails — currently the inner close is infallible after the first call, so this only surfaces internal invariant violations.

Source

pub fn is_valid(&self) -> bool

Check if the cursor is valid (not closed).

Source

pub fn get_state(&self) -> CursorState

Get the current cursor state.

Source

pub fn is_read_only(&self) -> bool

Check if the cursor is read-only.

Trait Implementations§

Source§

impl Drop for Cursor

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more