[][src]Struct xi_rope::tree::Cursor

pub struct Cursor<'a, N: 'a + NodeInfo> { /* fields omitted */ }

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.

Methods

impl<'a> Cursor<'a, RopeInfo>[src]

pub fn prev_codepoint(&mut self) -> Option<char>[src]

Get previous codepoint before cursor position, and advance cursor backwards.

pub fn next_codepoint(&mut self) -> Option<char>[src]

Get next codepoint after cursor position, and advance cursor.

pub fn peek_next_codepoint(&self) -> Option<char>[src]

Get the next codepoint after the cursor position, without advancing the cursor.

pub fn next_grapheme(&mut self) -> Option<usize>[src]

pub fn prev_grapheme(&mut self) -> Option<usize>[src]

impl<'a, N: NodeInfo> Cursor<'a, N>[src]

pub fn new(n: &'a Node<N>, position: usize) -> Cursor<'a, N>[src]

Create a new cursor at the given position.

pub fn total_len(&self) -> usize[src]

The length of the tree.

pub fn root(&self) -> &'a Node<N>[src]

Return a reference to the root node of the tree.

pub fn get_leaf(&self) -> Option<(&'a N::L, usize)>[src]

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)[src]

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 pos(&self) -> usize[src]

Get the position of the cursor.

pub fn is_boundary<M: Metric<N>>(&mut self) -> bool[src]

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: Metric<N>>(&mut self) -> Option<usize>[src]

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: Metric<N>>(&mut self) -> Option<usize>[src]

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: Metric<N>>(&mut self) -> Option<usize>[src]

Returns the current position if it is a boundary in this Metric, else behaves like next.

pub fn at_or_prev<M: Metric<N>>(&mut self) -> Option<usize>[src]

Returns the current position if it is a boundary in this Metric, else behaves like prev.

Important traits for CursorIter<'c, 'a, N, M>
pub fn iter<'c, M: Metric<N>>(&'c mut self) -> CursorIter<'c, 'a, N, M>[src]

Returns an iterator with this cursor over the given Metric.

Examples:

let text: Rope = "one line\ntwo line\nred line\nblue".into();
let mut cursor = Cursor::new(&text, 0);
let line_offsets = cursor.iter::<LinesMetric>().collect::<Vec<_>>();
assert_eq!(line_offsets, vec![9, 18, 27]);

pub fn next_leaf(&mut self) -> Option<(&'a N::L, usize)>[src]

Move to beginning of next leaf.

Return value: same as get_leaf.

pub fn prev_leaf(&mut self) -> Option<(&'a N::L, usize)>[src]

Move to beginning of previous leaf.

Return value: same as get_leaf.

Auto Trait Implementations

impl<'a, N> Send for Cursor<'a, N> where
    N: Send + Sync,
    <N as NodeInfo>::L: Send + Sync

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

impl<'a, N> Sync for Cursor<'a, N> where
    N: Send + Sync,
    <N as NodeInfo>::L: Send + Sync

impl<'a, N> UnwindSafe for Cursor<'a, N> where
    N: RefUnwindSafe,
    <N as NodeInfo>::L: RefUnwindSafe

impl<'a, N> RefUnwindSafe for Cursor<'a, N> where
    N: RefUnwindSafe,
    <N as NodeInfo>::L: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]