Skip to main content

NodeList

Struct NodeList 

Source
pub struct NodeList<BackendT>(pub Vec<Node<BackendT>>)
where
    BackendT: TreeBackend;
Expand description

Tree node list.

Tuple Fields§

§0: Vec<Node<BackendT>>

Implementations§

Source§

impl<BackendT> NodeList<BackendT>
where BackendT: TreeBackend,

Source

pub fn iter(&self, only_expanded: bool) -> NodeIterator<'_, BackendT>

Iterate nodes in visual order from top to bottom.

When only_expanded is true will skip the children of collapsed branches.

Source

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

Get node at path.

Source

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

Get node at path.

Source

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

Fill path to node.

Returns true if found.

Source

pub fn add( &mut self, depth: usize, kind: NodeKind, id: BackendT::ID, representation: Representation, )

Add a node.

Examples found in repository?
examples/file_browser.rs (line 115)
96fn node_list(depth: usize, directory: &PathBuf) -> Result<NodeList<FileBackend>, io::Error> {
97    let mut list = NodeList::default();
98
99    for entry in read_dir(directory)? {
100        let entry = entry?;
101
102        let kind = if entry.file_type()?.is_dir() { NodeKind::Branch } else { NodeKind::Leaf };
103
104        let file_name = entry.file_name();
105        let file_name = file_name.to_string_lossy();
106
107        // We'll use different styles for leaves and branches
108        let mut representation = Representation::default();
109        if kind.is_branch() {
110            representation.append_styled(file_name, Style::primary().combine(Effect::Bold));
111        } else {
112            representation.append(file_name);
113        }
114
115        list.add(depth, kind, entry.path(), representation);
116    }
117
118    list.0.sort_by(|a: &Node<FileBackend>, b: &Node<FileBackend>| a.id.cmp(&b.id));
119
120    Ok(list)
121}
Source

pub fn insert( &mut self, index: usize, depth: usize, kind: NodeKind, id: BackendT::ID, representation: Representation, )

Insert a node.

Source

pub fn expand( &mut self, depth: Option<usize>, context: BackendT::Context, ) -> Result<(), BackendT::Error>
where BackendT::Context: Clone,

Expand branch nodes.

If depth is None will expand all depths.

If depth is 0 will do nothing.

Note that this will populate expanded nodes from the backend.

Source

pub fn collapse(&mut self, depth: Option<usize>)

Collapse branch nodes.

If depth is None will collapse all depths.

If depth is 0 will do nothing.

Trait Implementations§

Source§

impl<BackendT> Default for NodeList<BackendT>
where BackendT: TreeBackend,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<BackendT> From<Vec<Node<BackendT>>> for NodeList<BackendT>
where BackendT: TreeBackend,

Source§

fn from(vector: Vec<Node<BackendT>>) -> Self

Converts to this type from the input type.
Source§

impl<BackendT> FromIterator<Node<BackendT>> for NodeList<BackendT>
where BackendT: TreeBackend,

Source§

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

Creates a value from an iterator. Read more
Source§

impl<'this, BackendT> IntoIterator for &'this NodeList<BackendT>
where BackendT: TreeBackend,

Source§

type Item = &'this Node<BackendT>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'this, Node<BackendT>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'this, BackendT> IntoIterator for &'this mut NodeList<BackendT>
where BackendT: TreeBackend,

Source§

type Item = &'this mut Node<BackendT>

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'this, Node<BackendT>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<BackendT> Freeze for NodeList<BackendT>

§

impl<BackendT> RefUnwindSafe for NodeList<BackendT>
where <BackendT as TreeBackend>::ID: RefUnwindSafe, <BackendT as TreeBackend>::Data: RefUnwindSafe, BackendT: RefUnwindSafe,

§

impl<BackendT> Send for NodeList<BackendT>
where <BackendT as TreeBackend>::ID: Send, <BackendT as TreeBackend>::Data: Send, BackendT: Send,

§

impl<BackendT> Sync for NodeList<BackendT>
where <BackendT as TreeBackend>::ID: Sync, <BackendT as TreeBackend>::Data: Sync, BackendT: Sync,

§

impl<BackendT> Unpin for NodeList<BackendT>
where <BackendT as TreeBackend>::ID: Unpin, <BackendT as TreeBackend>::Data: Unpin, BackendT: Unpin,

§

impl<BackendT> UnsafeUnpin for NodeList<BackendT>

§

impl<BackendT> UnwindSafe for NodeList<BackendT>
where <BackendT as TreeBackend>::ID: UnwindSafe, <BackendT as TreeBackend>::Data: UnwindSafe, BackendT: 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.