Skip to main content

Cursor

Struct Cursor 

Source
pub struct Cursor<'id, 's, 'a, T: Flat, Root: Flat, B: Buf> { /* private fields */ }
Expand description

Chainable cursor over a Session.

Provides a fluent API for navigating and mutating a region. Each method consumes self (by move), preventing borrow conflicts. For complex navigation patterns or batch operations, use Session methods directly.

use nearest::{Flat, Near, Region, near};

#[derive(Flat, Debug)]
struct Outer { inner: Near<Inner> }

#[derive(Flat, Debug, Clone, Copy)]
struct Inner { value: u32 }

let mut region = Region::new(Outer::make(near(Inner { value: 1 })));
assert_eq!(region.inner.get().value, 1);

region.session(|s| {
  s.cursor()
    .at(|root| &root.inner)       // navigate to inner Near<Inner>
    .follow()                      // dereference the Near pointer
    .set(Inner { value: 42 });     // overwrite
});

assert_eq!(region.inner.get().value, 42);

Implementations§

Source§

impl<'id, 's, 'a, T: Flat, Root: Flat, B: Buf> Cursor<'id, 's, 'a, T, Root, B>

Source

pub fn at<U: Flat>( self, f: impl FnOnce(&T) -> &U, ) -> Cursor<'id, 's, 'a, U, Root, B>

Navigate to a sub-field.

Source

pub fn get(&self) -> &T

Read the value at this cursor’s position.

Source

pub const fn pin(self) -> Ref<'id, T>

Extract the Ref at this cursor’s position.

Source§

impl<T: Flat + Copy, Root: Flat, B: Buf> Cursor<'_, '_, '_, T, Root, B>

Source

pub fn set(self, val: T)

Overwrite the value at this cursor’s position.

Source§

impl<T: Flat, Root: Flat, B: Buf> Cursor<'_, '_, '_, T, Root, B>

Source

pub fn write_with(self, builder: impl Emit<T>)

Overwrite the value at this cursor’s position using a builder.

Source§

impl<'id, 's, 'a, U: Flat, Root: Flat, B: Buf> Cursor<'id, 's, 'a, Near<U>, Root, B>

Source

pub fn splice(self, builder: impl Emit<U>)

Replace the target of this Near<U> pointer with freshly emitted data.

Source

pub fn follow(self) -> Cursor<'id, 's, 'a, U, Root, B>

Follow the Near pointer, returning a cursor at the target.

Source§

impl<U: Flat, Root: Flat, B: Buf> Cursor<'_, '_, '_, NearList<U>, Root, B>

Source

pub fn splice_list<E: Emit<U>, I>(self, items: I)
where I: IntoIterator<Item = E>, I::IntoIter: ExactSizeIterator,

Replace the elements of this NearList<U>.

Source

pub fn filter_list(self, pred: impl FnMut(&U) -> bool)

Remove elements that do not satisfy a predicate.

Auto Trait Implementations§

§

impl<'id, 's, 'a, T, Root, B> Freeze for Cursor<'id, 's, 'a, T, Root, B>

§

impl<'id, 's, 'a, T, Root, B> RefUnwindSafe for Cursor<'id, 's, 'a, T, Root, B>

§

impl<'id, 's, 'a, T, Root, B> Send for Cursor<'id, 's, 'a, T, Root, B>
where T: Send, Root: Send + Sync, B: Send,

§

impl<'id, 's, 'a, T, Root, B> Sync for Cursor<'id, 's, 'a, T, Root, B>
where T: Sync, Root: Send + Sync, B: Sync,

§

impl<'id, 's, 'a, T, Root, B> Unpin for Cursor<'id, 's, 'a, T, Root, B>
where T: Unpin,

§

impl<'id, 's, 'a, T, Root, B> UnsafeUnpin for Cursor<'id, 's, 'a, T, Root, B>

§

impl<'id, 's, 'a, T, Root, B> !UnwindSafe for Cursor<'id, 's, 'a, T, Root, 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, 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.