Skip to main content

Location

Struct Location 

Source
pub struct Location<T: Clone> {
    pub cursor: Tree<T>,
    pub path: Rc<Path<T>>,
}
Expand description

Represents a location (cursor) within a tree.

A location combines a cursor pointing to the current tree node and a path providing context for navigation within the overall tree structure.

Fields§

§cursor: Tree<T>

The current tree node being focused on.

§path: Rc<Path<T>>

The path representing the context of this location within the overall tree.

Implementations§

Source§

impl<T: Clone> Location<T>

Source

pub fn new(tree: Tree<T>) -> Self

Creates a new location from a tree.

§Arguments
  • tree - The tree to create a location from.
§Returns

A new Location instance with the given tree as cursor.

Source

pub fn go_left(self) -> Option<Self>

Moves the cursor to the left sibling.

§Returns
  • Some(Location) - If there is a left sibling.
  • None - If there is no left sibling or the location is at the top.
Source

pub fn go_right(self) -> Option<Self>

Moves the cursor to the right sibling.

§Returns
  • Some(Location) - If there is a right sibling.
  • None - If there is no right sibling or the location is at the top.
Source

pub fn go_up(self) -> Option<Self>

Moves the cursor to the parent node.

§Returns
  • Some(Location) - If there is a parent node.
  • None - If the location is at the top.
Source

pub fn go_down(self) -> Option<Self>

Moves the cursor to the first child node.

§Returns
  • Some(Location) - If the current node is a section with at least one child.
  • None - If the current node is an item or an empty section.
Source

pub fn get_nth(self, n: usize) -> Option<Self>

Gets the nth child of the current node.

This is equivalent to n calls to go_right().

§Arguments
  • n - The index of the child to navigate to.
§Returns
  • Some(Location) - If the child exists.
  • None - If the child doesn’t exist or the current node is an item.
Source

pub fn change(self, tree: Tree<T>) -> Self

Replaces the current node with a new tree.

§Arguments
  • tree - The new tree to replace the current node with.
§Returns

A new location with the updated cursor.

Source

pub fn insert_right(self, tree: Tree<T>) -> Option<Self>

Inserts a new tree to the right of the current node.

§Arguments
  • tree - The tree to insert.
§Returns
  • Some(Location) - If the insertion was successful.
  • None - If the location is at the top.
Source

pub fn insert_left(self, tree: Tree<T>) -> Option<Self>

Inserts a new tree to the left of the current node.

§Arguments
  • tree - The tree to insert.
§Returns
  • Some(Location) - If the insertion was successful.
  • None - If the location is at the top.
Source

pub fn insert_down(self, tree: Tree<T>) -> Option<Self>

Inserts a new tree as the first child of the current node.

§Arguments
  • tree - The tree to insert.
§Returns
  • Some(Location) - If the current node is a section.
  • None - If the current node is an item.
Source

pub fn delete(self) -> Option<Self>

Deletes the current node and moves the cursor to a sibling or parent.

§Returns
  • Some(Location) - If the deletion was successful.
  • None - If the location is at the top.

Trait Implementations§

Source§

impl<T: Clone + Clone> Clone for Location<T>

Source§

fn clone(&self) -> Location<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Clone> Debug for Location<T>

Source§

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

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

impl<T: PartialEq + Clone> PartialEq for Location<T>

Source§

fn eq(&self, other: &Location<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Clone> StructuralPartialEq for Location<T>

Auto Trait Implementations§

§

impl<T> Freeze for Location<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Location<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Location<T>

§

impl<T> !Sync for Location<T>

§

impl<T> Unpin for Location<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Location<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Location<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.