pub struct Cursor {
pub index: usize,
pub node: Arc<Node>,
pub parent: Option<Box<Cursor>>,
}Expand description
A cursor pointing to a specific position in a prolly tree.
Cursors provide efficient navigation through the tree structure without recursion. They maintain a reference to the current node and an index within that node, with optional parent linkage for upward navigation.
§Cloning
Cursors are cloneable. Cloned cursors are independent of the original - advancing one does not affect the other.
Fields§
§index: usizeCurrent position within the node (0-based index)
node: Arc<Node>Current node (Arc for efficient cloning)
parent: Option<Box<Cursor>>Parent cursor for upward navigation
Implementations§
Source§impl Cursor
impl Cursor
Sourcepub fn at_item<S: Store>(
store: &S,
tree: &Tree,
key: &[u8],
) -> Result<Self, Error>
pub fn at_item<S: Store>( store: &S, tree: &Tree, key: &[u8], ) -> Result<Self, Error>
Navigate to the position of a key in the tree.
Follows the Arbor spec’s CursorAtItem algorithm:
- Find index in current node
- If leaf, done
- Otherwise, recurse to child with parent linkage
§Arguments
store- The storage backend to load nodes fromtree- The tree to navigatekey- The key to position at
§Returns
Ok(Cursor)- A cursor positioned at or near the keyErr- If a storage error occurs
§Behavior
- If the tree is empty, returns a cursor with an empty node (is_valid() == false)
- If the key exists, positions at that exact key
- If the key doesn’t exist, positions at the greatest key <= target
Sourcepub fn get_key(&self) -> Option<&[u8]>
pub fn get_key(&self) -> Option<&[u8]>
Get the current key at the cursor position.
§Returns
Some(&[u8])- The key at the current positionNone- If the cursor is invalid (empty node or index out of bounds)
Sourcepub fn get_value(&self) -> Option<&[u8]>
pub fn get_value(&self) -> Option<&[u8]>
Get the current value at the cursor position.
Only returns a value for leaf nodes. Internal nodes store CIDs, not values.
§Returns
Some(&[u8])- The value at the current position (leaf nodes only)None- If the cursor is invalid or at an internal node
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Check if the cursor is valid.
A cursor is valid if:
- The node is not empty
- The index is within bounds
§Returns
true if the cursor points to a valid entry, false otherwise.
Sourcepub fn is_at_end(&self) -> bool
pub fn is_at_end(&self) -> bool
Check if the cursor is at the end of its current node.
§Returns
true if the cursor is at the last entry of the node, false otherwise.
Sourcepub fn advance<S: Store>(&mut self, store: &S) -> bool
pub fn advance<S: Store>(&mut self, store: &S) -> bool
Advance the cursor to the next entry in the tree.
Follows the Arbor spec’s AdvanceCursor algorithm:
- Try to advance within current node
- If at end, navigate up to parent
- Advance parent and load next child
- Descend to leftmost leaf of next subtree
§Arguments
store- The storage backend to load nodes from
§Returns
trueif successfully advanced to next entryfalseif at end of tree (no more entries)
§Behavior
After returning false, the cursor becomes invalid (is_valid() returns false).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cursor
impl RefUnwindSafe for Cursor
impl Send for Cursor
impl Sync for Cursor
impl Unpin for Cursor
impl UnsafeUnpin for Cursor
impl UnwindSafe for Cursor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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