pub enum NodeKind {
Branch,
Leaf,
}Expand description
Tree node kind.
Variants§
Implementations§
Source§impl NodeKind
impl NodeKind
Sourcepub fn is_branch(&self) -> bool
pub fn is_branch(&self) -> bool
Whether the node is a branch.
Examples found in repository?
examples/file_browser.rs (line 109)
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}Trait Implementations§
impl Copy for NodeKind
impl Eq for NodeKind
impl StructuralPartialEq for NodeKind
Auto Trait Implementations§
impl Freeze for NodeKind
impl RefUnwindSafe for NodeKind
impl Send for NodeKind
impl Sync for NodeKind
impl Unpin for NodeKind
impl UnsafeUnpin for NodeKind
impl UnwindSafe for NodeKind
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