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,
impl<BackendT> NodeList<BackendT>where
BackendT: TreeBackend,
Sourcepub fn iter(&self, only_expanded: bool) -> NodeIterator<'_, BackendT> ⓘ
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.
Sourcepub fn at_path_mut(&mut self, path: NodePath) -> Option<&mut Node<BackendT>>
pub fn at_path_mut(&mut self, path: NodePath) -> Option<&mut Node<BackendT>>
Get node at path.
Sourcepub fn fill_path(&self, path: &mut NodePath, node: &Node<BackendT>) -> bool
pub fn fill_path(&self, path: &mut NodePath, node: &Node<BackendT>) -> bool
Fill path to node.
Returns true if found.
Sourcepub fn add(
&mut self,
depth: usize,
kind: NodeKind,
id: BackendT::ID,
representation: Representation,
)
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}Sourcepub fn insert(
&mut self,
index: usize,
depth: usize,
kind: NodeKind,
id: BackendT::ID,
representation: Representation,
)
pub fn insert( &mut self, index: usize, depth: usize, kind: NodeKind, id: BackendT::ID, representation: Representation, )
Insert a node.
Trait Implementations§
Source§impl<BackendT> Default for NodeList<BackendT>where
BackendT: TreeBackend,
impl<BackendT> Default for NodeList<BackendT>where
BackendT: TreeBackend,
Source§impl<BackendT> FromIterator<Node<BackendT>> for NodeList<BackendT>where
BackendT: TreeBackend,
impl<BackendT> FromIterator<Node<BackendT>> for NodeList<BackendT>where
BackendT: TreeBackend,
Source§impl<'this, BackendT> IntoIterator for &'this NodeList<BackendT>where
BackendT: TreeBackend,
impl<'this, BackendT> IntoIterator for &'this NodeList<BackendT>where
BackendT: TreeBackend,
Source§impl<'this, BackendT> IntoIterator for &'this mut NodeList<BackendT>where
BackendT: TreeBackend,
impl<'this, BackendT> IntoIterator for &'this mut NodeList<BackendT>where
BackendT: TreeBackend,
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>
impl<BackendT> Sync for NodeList<BackendT>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more