Skip to main content

Node

Struct Node 

Source
pub struct Node<BackendT, ContextT, ErrorT, IdT, DataT> {
    pub depth: usize,
    pub kind: NodeKind,
    pub id: IdT,
    pub representation: Representation,
    pub representation_size: XY<usize>,
    pub branch_state: BranchState,
    pub children: Option<NodeList<BackendT, ContextT, ErrorT, IdT, DataT>>,
    pub data: Option<DataT>,
    /* private fields */
}
Expand description

Tree node.

Fields§

§depth: usize

Depth.

§kind: NodeKind

Kind.

§id: IdT

ID.

§representation: Representation

Representation.

§representation_size: XY<usize>

Representation size.

Cached so we only have to calculate it once.

§branch_state: BranchState

State for Branch node.

§children: Option<NodeList<BackendT, ContextT, ErrorT, IdT, DataT>>

Children for Branch node.

§data: Option<DataT>

Data.

Implementations§

Source§

impl<BackendT, ContextT, ErrorT, IdT, DataT> Node<BackendT, ContextT, ErrorT, IdT, DataT>
where BackendT: TreeBackend<ContextT, ErrorT, IdT, DataT>,

Source

pub fn new( depth: usize, kind: NodeKind, id: IdT, representation: Representation, ) -> Self

Constructor.

Source

pub fn symbol(&self, context: ContextT) -> Symbol<'_>

Symbol.

Its char count is always 1.

Source

pub fn at_path(&self, path: NodePath) -> Option<&Self>

Get node at path.

Source

pub fn at_path_mut(&mut self, path: NodePath) -> Option<&mut Self>

Get node at path.

Source

pub fn fill_path(&self, path: &mut NodePath, node: &Self) -> bool

Fill path to node.

Returns true if found.

Source

pub fn populate( &mut self, depth: Option<usize>, context: ContextT, ) -> Result<(), ErrorT>
where ContextT: Clone,

Fetch nodes from backend.

If depth is None will populate all depths.

If depth is 0 will do nothing.

Source

pub fn add_child( &mut self, kind: NodeKind, id: IdT, representation: Representation, )

Add a child node.

Source

pub fn insert_child( &mut self, index: usize, kind: NodeKind, id: IdT, representation: Representation, )

Inserts a child node.

Source

pub fn expand_branch(&mut self, context: ContextT) -> Result<bool, ErrorT>
where ContextT: Clone,

Expand the branch.

Will return false if not a Branch or already expanded.

Source

pub fn collapse_branch(&mut self) -> bool

Collapse the branch.

Will return false if not a Branch or already collapsed.

Source

pub fn toggle_branch_state(&mut self, context: ContextT) -> Result<(), ErrorT>
where ContextT: Clone,

Toggle the branch state.

Expand if collapsed, collapse if expanded.

Will do nothing if not a Branch.

Source

pub fn data( &mut self, context: ContextT, ) -> Result<Option<Cow<'_, DataT>>, ErrorT>
where DataT: Clone,

Data.

If not already cached will fetch it from the backend.

Trait Implementations§

Source§

impl<BackendT, ContextT, ErrorT, IdT, DataT> FromIterator<Node<BackendT, ContextT, ErrorT, IdT, DataT>> for NodeList<BackendT, ContextT, ErrorT, IdT, DataT>

Source§

fn from_iter<IteratorT>(iterator: IteratorT) -> Self
where IteratorT: IntoIterator<Item = Node<BackendT, ContextT, ErrorT, IdT, DataT>>,

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<BackendT, ContextT, ErrorT, IdT, DataT> Freeze for Node<BackendT, ContextT, ErrorT, IdT, DataT>
where IdT: Freeze, DataT: Freeze,

§

impl<BackendT, ContextT, ErrorT, IdT, DataT> RefUnwindSafe for Node<BackendT, ContextT, ErrorT, IdT, DataT>
where IdT: RefUnwindSafe, DataT: RefUnwindSafe, BackendT: RefUnwindSafe, ContextT: RefUnwindSafe, ErrorT: RefUnwindSafe,

§

impl<BackendT, ContextT, ErrorT, IdT, DataT> Send for Node<BackendT, ContextT, ErrorT, IdT, DataT>
where IdT: Send, DataT: Send, BackendT: Send, ContextT: Send, ErrorT: Send,

§

impl<BackendT, ContextT, ErrorT, IdT, DataT> Sync for Node<BackendT, ContextT, ErrorT, IdT, DataT>
where IdT: Sync, DataT: Sync, BackendT: Sync, ContextT: Sync, ErrorT: Sync,

§

impl<BackendT, ContextT, ErrorT, IdT, DataT> Unpin for Node<BackendT, ContextT, ErrorT, IdT, DataT>
where IdT: Unpin, DataT: Unpin, BackendT: Unpin, ContextT: Unpin, ErrorT: Unpin,

§

impl<BackendT, ContextT, ErrorT, IdT, DataT> UnsafeUnpin for Node<BackendT, ContextT, ErrorT, IdT, DataT>
where IdT: UnsafeUnpin, DataT: UnsafeUnpin,

§

impl<BackendT, ContextT, ErrorT, IdT, DataT> UnwindSafe for Node<BackendT, ContextT, ErrorT, IdT, DataT>
where IdT: UnwindSafe, DataT: UnwindSafe, BackendT: UnwindSafe, ContextT: UnwindSafe, ErrorT: UnwindSafe,

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.
Source§

impl<T> With for T

Source§

fn wrap_with<U, F>(self, f: F) -> U
where F: FnOnce(Self) -> U,

Calls the given closure and return the result. Read more
Source§

fn with<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure on self.
Source§

fn try_with<E, F>(self, f: F) -> Result<Self, E>
where F: FnOnce(&mut Self) -> Result<(), E>,

Calls the given closure on self.
Source§

fn with_if<F>(self, condition: bool, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure if condition == true.