Struct RestrictedCursor

Source
pub struct RestrictedCursor<'a, T> {
    pub preceding: Option<Preceding<NonNull<Node<T>>>>,
    pub current: Option<NonNull<Node<T>>>,
    pub root: &'a mut Option<NonNull<Node<T>>>,
    pub guarded_nodes: Vec<NonNull<Node<T>>>,
}
Expand description

A cursor which can be used to mutate element, but only in such a way that it does not remove elements in self.guarded_nodes. This allows for a semi-mutable cursor on the upper portion of a syntax tree while maintaining a mutable cursor on the lower portion.

Fields§

§preceding: Option<Preceding<NonNull<Node<T>>>>

The preceding element, mutably accessing this is unsafe.

§current: Option<NonNull<Node<T>>>

The current element, mutably accessing this is unsafe.

§root: &'a mut Option<NonNull<Node<T>>>

The current root element, mutably accessing this is unsafe.

§guarded_nodes: Vec<NonNull<Node<T>>>

The set of nodes which cannot be removed, mutably accessing this is unsafe.

Implementations§

Source§

impl<'a, T> RestrictedCursor<'a, T>

Source

pub fn current(&self) -> Option<&T>

Get the current element.

Returns None if the current element is None or if the current element is the lower bound.

Source

pub fn peek_move_preceding(&mut self) -> Option<&T>

Moves the cursor to the preceding element returning a reference to the new element if one is present, otherwise returning None.

Source

pub fn move_preceding(&mut self) -> bool

Moves the cursor to the preceding element.

If there is no preceding element the cursor is not moved.

Source

pub fn move_next(&mut self)

Moves the cursor to the next element if there is some current element and the next element is within the bounds of the cursor (when splitting a mutable cursor, an immutable cursor is produced where its bound restrict it to element above the mutable cursor).

Source

pub fn move_child(&mut self)

Moves the cursor to the child element if there is some current element and the child element is within the bounds of the cursor (when splitting a mutable cursor, an immutable cursor is produced where its bound restrict it to element above the mutable cursor).

Source

pub fn move_parent(&mut self) -> bool

Moves the cursor through preceding elements until reaching a parent, if no parent is found, the cursor is reset to its original position.

Returns true if the cursor was moved to a parent, or false if not.

Source

pub fn move_successor(&mut self) -> bool

Moves the cursor to the successor element if one can be found. If there is no successor element the cursor is reset to its original position and is not moved.

Returns true if the cursor was moved to a successor, or false if not.

Source

pub fn move_predecessor(&mut self) -> bool

Moves the cursor to the predecessor element if one can be found. If there is no predecessor element the cursor is reset to its original position and is not moved.

Returns true if the cursor was moved to a predecessor, or false if not.

Source

pub fn peek_next(&self) -> Option<&T>

Returns a reference to the next element.

Source

pub fn peek_parent(&self) -> Option<&T>

Returns a reference to the parent element.

Wrapper around self.peek_preceding().and_then(Preceding::parent).

Source

pub fn peek_previous(&self) -> Option<&T>

Returns a reference to the previous element.

Wrapper around self.peek_preceding().and_then(Preceding::previous) .

Source

pub fn peek_preceding(&self) -> Option<Preceding<&T>>

Returns a reference to the preceding element.

Source

pub fn peek_child(&self) -> Option<&T>

Returns a reference to the child element.

Source

pub fn current_mut(&self) -> Option<&mut T>

Get the current element.

Source

pub fn remove_current(&mut self)

Removes the current node if it is not a guarded node.

When removing a node with a child node, the child node is removed.

Returns if the node was removed.

Trait Implementations§

Source§

impl<'a, T: Debug> Debug for RestrictedCursor<'a, T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a, T> From<RestrictedCursor<'a, T>> for Cursor<'a, T>

Source§

fn from(cursor: RestrictedCursor<'a, T>) -> Cursor<'a, T>

Converts to this type from the input type.

Auto Trait Implementations§

§

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

§

impl<'a, T> RefUnwindSafe for RestrictedCursor<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for RestrictedCursor<'a, T>

§

impl<'a, T> !Sync for RestrictedCursor<'a, T>

§

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

§

impl<'a, T> !UnwindSafe for RestrictedCursor<'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.