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>
impl<'a, T> RestrictedCursor<'a, T>
Sourcepub fn current(&self) -> Option<&T>
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.
Sourcepub fn peek_move_preceding(&mut self) -> Option<&T>
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
.
Sourcepub fn move_preceding(&mut self) -> bool
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.
Sourcepub fn move_next(&mut self)
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).
Sourcepub fn move_child(&mut self)
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).
Sourcepub fn move_parent(&mut self) -> bool
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.
Sourcepub fn move_successor(&mut self) -> bool
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.
Sourcepub fn move_predecessor(&mut self) -> bool
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.
Sourcepub fn peek_parent(&self) -> Option<&T>
pub fn peek_parent(&self) -> Option<&T>
Returns a reference to the parent element.
Wrapper around self.peek_preceding().and_then(Preceding::parent)
.
Sourcepub fn peek_previous(&self) -> Option<&T>
pub fn peek_previous(&self) -> Option<&T>
Returns a reference to the previous element.
Wrapper around self.peek_preceding().and_then(Preceding::previous)
.
Sourcepub fn peek_preceding(&self) -> Option<Preceding<&T>>
pub fn peek_preceding(&self) -> Option<Preceding<&T>>
Returns a reference to the preceding element.
Sourcepub fn peek_child(&self) -> Option<&T>
pub fn peek_child(&self) -> Option<&T>
Returns a reference to the child element.
Sourcepub fn current_mut(&self) -> Option<&mut T>
pub fn current_mut(&self) -> Option<&mut T>
Get the current element.
Sourcepub fn remove_current(&mut self)
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.