Cursor

Struct Cursor 

Source
pub struct Cursor<'a, T: 'a> { /* private fields */ }
Expand description

Streaming iterator providing mutable components and a capability to look back/ahead.

See documentation of CursorItem.

Implementations§

Source§

impl<'a, T> Cursor<'a, T>

Source

pub fn next( &mut self, ) -> Option<(Slice<'_, T>, CursorItem<'_, T>, Slice<'_, T>)>

Advance the stream to the next item.

Examples found in repository?
examples/cursor.rs (line 30)
8fn main() {
9    let mut storage = froggy::Storage::new();
10    // initialize the first two Fibbo numbers
11    let mut first = storage.create(Fibbo {
12        prev: Vec::new(),
13        value: 1,
14    });
15    let mut second = storage.create(Fibbo {
16        prev: vec![first.clone()],
17        value: 0,
18    });
19    // initialize the other ones
20    for _ in 0 .. 10 {
21        let next = storage.create(Fibbo {
22            prev: vec![first, second.clone()],
23            value: 0,
24        });
25        first = second;
26        second = next;
27    }
28    // compute them with look-back
29    let mut cursor = storage.cursor();
30    cursor.next().unwrap(); //skip first
31    while let Some((left, mut item, _)) = cursor.next() {
32        item.value = item.prev.iter().map(|prev|
33            left.get(prev).unwrap().value
34            ).sum();
35        println!("{}", item.value);
36    }
37}
Source

pub fn prev( &mut self, ) -> Option<(Slice<'_, T>, CursorItem<'_, T>, Slice<'_, T>)>

Advance the stream to the previous item.

Trait Implementations§

Source§

impl<'a, T: Debug + 'a> Debug for Cursor<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for Cursor<'a, T>

§

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

§

impl<'a, T> Send for Cursor<'a, T>
where T: Send,

§

impl<'a, T> Sync for Cursor<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for Cursor<'a, T>

§

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

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.