[][src]Struct c2rust_refactor::util::cursor::Cursor

pub struct Cursor<T> { /* fields omitted */ }

A Cursor indicates a position within a sequence of Ts. The position can be anywhere within the sequence, including before the first item and after the last.

Marks

In addition to moving through and manipulating the sequence, Cursors also permit marking the current position so it can be referenced in later operations. These marks remain in place even if items are inserted, removed, or replaced before or after the mark. (But replacing a range of items will invalidate all marks between the replaced items.)

Methods

impl<T> Cursor<T>[src]

pub fn new() -> Cursor<T>[src]

pub fn from_vec(orig: Vec<T>) -> Cursor<T>[src]

pub fn into_vec(self) -> Vec<T>[src]

pub fn retract(&mut self)[src]

Move the cursor back by one position.

pub fn retract_by(&mut self, n: usize)[src]

Move the cursor back by n positions.

pub fn advance(&mut self)[src]

Move the cursor forward by one position.

pub fn advance_by(&mut self, steps: usize)[src]

Move the cursor forward by n positions.

pub fn mark(&mut self) -> Mark[src]

Return a Mark indicating the current position. As long as the mark remains valid, seek can be used to return to this position.

pub fn seek(&mut self, mark: Mark)[src]

Return to a previously marked position. Panics if the mark is invalid.

pub fn eof(&self) -> bool[src]

Checks if the cursor is positioned at the end of the sequence.

pub fn insert(&mut self, x: T)[src]

Insert an element at the current position. Afterward, the cursor will point after the inserted element.

pub fn insert_multi(&mut self, xs: Vec<T>)[src]

Insert several elements at the current position. Afterward, the cursor will point after the inserted elements.

pub fn remove(&mut self) -> T[src]

Remove the element after the current position. Panics if the current position is at the end of the sequence.

pub fn remove_multi(&mut self, n: usize) -> Vec<T>[src]

Remove n elements after the current position.

pub fn next(&self) -> &T[src]

Return a reference to the element immediately after the current position.

pub fn advance_until<F: FnMut(&T) -> bool>(&mut self, pred: F)[src]

Advance until an element matches pred. The cursor is left pointing just before the matching element. If no element matches, the cursor points at the end of the sequence.

pub fn remove_to_mark(&mut self, m: Mark) -> Vec<T>[src]

Remove elements between the current position and the given mark. The mark must not be behind the current position in the buffer.

pub fn replace<F>(&mut self, func: F) where
    F: FnOnce(T) -> T, 
[src]

Replace the element after the cursor by transforming it with func. Does not move the cursor.

pub fn replace_range<F>(&mut self, start: Mark, end: Mark, func: F) where
    F: FnOnce(Vec<T>) -> Vec<T>, 
[src]

Extract the elements between start and end, transform them using func, and insert the results in their place. Afterward, the cursor points past the end of the replacement sequnece.

pub fn advance_until_match<F, R>(&mut self, func: F) -> Option<R> where
    F: FnMut(&T) -> Option<R>, 
[src]

Check items with func until it matches (returns Some). Returns the result of func on the matched item, and leaves the cursor just before the item itself.

pub fn debug(&self)[src]

Auto Trait Implementations

impl<T> Send for Cursor<T> where
    T: Send

impl<T> Sync for Cursor<T> where
    T: Sync

Blanket Implementations

impl<T> Lone for T[src]

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

impl<T, U> TryInto 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<E> SpecializationError for E[src]

impl<T> Erased for T[src]

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

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

impl<T> Same for T

type Output = T

Should always be Self

impl<T> MaybeResult for T[src]

impl<'a, T> Captures for T where
    T: ?Sized
[src]

impl<T> Erased for T

impl<T> Make for T[src]

impl<T> Slottable for T[src]