Struct Cursor
pub struct Cursor<'a, N>where
N: 'a + NodeInfo,{ /* private fields */ }Expand description
A data structure for traversing boundaries in a tree.
It is designed to be efficient both for random access and for iteration. The
cursor itself is agnostic to which Metric is used to determine boundaries, but
the methods to find boundaries are parametrized on the Metric.
A cursor can be valid or invalid. It is always valid when created or after
set is called, and becomes invalid after prev
or next fails to find a boundary.
Implementations§
§impl<'a> Cursor<'a, RopeInfo>
impl<'a> Cursor<'a, RopeInfo>
pub fn prev_codepoint(&mut self) -> Option<char>
pub fn prev_codepoint(&mut self) -> Option<char>
Get previous codepoint before cursor position, and advance cursor backwards.
pub fn next_codepoint(&mut self) -> Option<char>
pub fn next_codepoint(&mut self) -> Option<char>
Get next codepoint after cursor position, and advance cursor.
pub fn peek_next_codepoint(&self) -> Option<char>
pub fn peek_next_codepoint(&self) -> Option<char>
Get the next codepoint after the cursor position, without advancing the cursor.
pub fn next_grapheme(&mut self) -> Option<usize>
pub fn prev_grapheme(&mut self) -> Option<usize>
§impl<'a, N> Cursor<'a, N>where
N: NodeInfo,
impl<'a, N> Cursor<'a, N>where
N: NodeInfo,
pub fn new(n: &'a Node<N>, position: usize) -> Cursor<'a, N>
pub fn new(n: &'a Node<N>, position: usize) -> Cursor<'a, N>
Create a new cursor at the given position.
pub fn get_leaf(&self) -> Option<(&'a <N as NodeInfo>::L, usize)>
pub fn get_leaf(&self) -> Option<(&'a <N as NodeInfo>::L, usize)>
Get the current leaf of the cursor.
If the cursor is valid, returns the leaf containing the current position, and the offset of the current position within the leaf. That offset is equal to the leaf length only at the end, otherwise it is less than the leaf length.
pub fn set(&mut self, position: usize)
pub fn set(&mut self, position: usize)
Set the position of the cursor.
The cursor is valid after this call.
Precondition: position is less than or equal to the length of the tree.
pub fn is_boundary<M>(&mut self) -> boolwhere
M: Metric<N>,
pub fn is_boundary<M>(&mut self) -> boolwhere
M: Metric<N>,
Determine whether the current position is a boundary.
Note: the beginning and end of the tree may or may not be boundaries, depending on the
metric. If the metric is not can_fragment, then they always are.
pub fn prev<M>(&mut self) -> Option<usize>where
M: Metric<N>,
pub fn prev<M>(&mut self) -> Option<usize>where
M: Metric<N>,
Moves the cursor to the previous boundary.
When there is no previous boundary, returns None and the cursor becomes invalid.
Return value: the position of the boundary, if it exists.
pub fn next<M>(&mut self) -> Option<usize>where
M: Metric<N>,
pub fn next<M>(&mut self) -> Option<usize>where
M: Metric<N>,
Moves the cursor to the next boundary.
When there is no next boundary, returns None and the cursor becomes invalid.
Return value: the position of the boundary, if it exists.
pub fn at_or_next<M>(&mut self) -> Option<usize>where
M: Metric<N>,
pub fn at_or_next<M>(&mut self) -> Option<usize>where
M: Metric<N>,
pub fn at_or_prev<M>(&mut self) -> Option<usize>where
M: Metric<N>,
pub fn at_or_prev<M>(&mut self) -> Option<usize>where
M: Metric<N>,
pub fn iter<'c, M>(&'c mut self) -> CursorIter<'c, 'a, N, M> ⓘwhere
M: Metric<N>,
pub fn iter<'c, M>(&'c mut self) -> CursorIter<'c, 'a, N, M> ⓘwhere
M: Metric<N>,
Auto Trait Implementations§
impl<'a, N> Freeze for Cursor<'a, N>
impl<'a, N> RefUnwindSafe for Cursor<'a, N>
impl<'a, N> Send for Cursor<'a, N>
impl<'a, N> Sync for Cursor<'a, N>
impl<'a, N> Unpin for Cursor<'a, N>
impl<'a, N> UnsafeUnpin for Cursor<'a, N>
impl<'a, N> UnwindSafe for Cursor<'a, N>
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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