pub struct Cursor<C> { /* private fields */ }Expand description
A generic cursor structure for navigating and manipulating collections.
It maintains a position within the collection
and provides methods to move forward, backward,
to the head, and to the tail of the collection.
It requires the collection to implement the Len trait.
The cyclic parameter allows the cursor to cycle through the collection.
Implementations§
Source§impl<C: Len> Cursor<C>
impl<C: Len> Cursor<C>
Sourcepub fn new(contents: C, position: usize, cyclic: bool) -> Self
pub fn new(contents: C, position: usize, cyclic: bool) -> Self
Constructs a new Cursor with the given contents, an initial position, and a cyclic flag.
If the given position is greater than the length of the contents,
it sets the position to the last item of the contents.
If cyclic is true, the cursor can cycle through the collection.
Sourcepub fn contents_mut(&mut self) -> &mut C
pub fn contents_mut(&mut self) -> &mut C
Returns a mutable reference to the contents.
Sourcepub fn replace_contents(&mut self, contents: C)
pub fn replace_contents(&mut self, contents: C)
Replaces the contents with new contents and adjusts the position if necessary.
pub fn shift(&mut self, backward: usize, forward: usize) -> bool
Sourcepub fn backward(&mut self) -> bool
pub fn backward(&mut self) -> bool
Moves the cursor one position backward, if possible. Returns true if successful.
If cyclic is true and the cursor is at the head, it moves to the tail.
Sourcepub fn forward(&mut self) -> bool
pub fn forward(&mut self) -> bool
Moves the cursor one position forward, if possible. Returns true if successful.
If cyclic is true and the cursor is at the tail, it moves to the head.
Sourcepub fn move_to_head(&mut self)
pub fn move_to_head(&mut self)
Moves the cursor to the head (start) of the contents.
Sourcepub fn move_to_tail(&mut self)
pub fn move_to_tail(&mut self)
Moves the cursor to the tail (end) of the contents.
pub fn move_to(&mut self, position: usize) -> bool
Trait Implementations§
Auto Trait Implementations§
impl<C> Freeze for Cursor<C>where
C: Freeze,
impl<C> RefUnwindSafe for Cursor<C>where
C: RefUnwindSafe,
impl<C> Send for Cursor<C>where
C: Send,
impl<C> Sync for Cursor<C>where
C: Sync,
impl<C> Unpin for Cursor<C>where
C: Unpin,
impl<C> UnsafeUnpin for Cursor<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for Cursor<C>where
C: UnwindSafe,
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