pub struct Tree<D: Display, V: Direction> {
pub root: D,
pub leaves: Vec<Tree<D, V>>,
/* private fields */
}Expand description
a simple recursive type which is able to render its components in a tree-like format
Fields§
§root: D§leaves: Vec<Tree<D, V>>Implementations§
Source§impl<D: Display, V: Direction> Tree<D, V>
impl<D: Display, V: Direction> Tree<D, V>
Sourcepub fn new(root: D) -> Self
pub fn new(root: D) -> Self
Examples found in repository?
examples/tree_up.rs (line 12)
10fn tree<P: AsRef<Path>>(p: P) -> io::Result<Tree<String, Up>> {
11 let result = fs::read_dir(&p)?.filter_map(|e| e.ok()).fold(
12 Tree::new(label(p.as_ref().canonicalize()?)),
13 |mut root, entry| {
14 let dir = entry.metadata().unwrap();
15 if dir.is_dir() {
16 root.push(tree(entry.path()).unwrap());
17 } else {
18 root.push(Tree::new(label(entry.path())));
19 }
20 root
21 },
22 );
23 Ok(result)
24}More examples
examples/tree.rs (line 12)
10fn tree<P: AsRef<Path>>(p: P) -> io::Result<Tree<String, Down>> {
11 let result = fs::read_dir(&p)?.filter_map(|e| e.ok()).fold(
12 Tree::new(label(p.as_ref().canonicalize()?)),
13 |mut root, entry| {
14 let dir = entry.metadata().unwrap();
15 if dir.is_dir() {
16 root.push(tree(entry.path()).unwrap());
17 } else {
18 root.push(Tree::new(label(entry.path())));
19 }
20 root
21 },
22 );
23 Ok(result)
24}pub fn with_leaves( self, leaves: impl IntoIterator<Item = impl Into<Tree<D, V>>>, ) -> Self
Sourcepub fn with_multiline(self, yes: bool) -> Self
pub fn with_multiline(self, yes: bool) -> Self
Ensure all lines for root are indented
Sourcepub fn with_glyphs(self, glyphs: GlyphPalette) -> Self
pub fn with_glyphs(self, glyphs: GlyphPalette) -> Self
Customize the rendering of this node
Source§impl<D: Display, V: Direction> Tree<D, V>
impl<D: Display, V: Direction> Tree<D, V>
Sourcepub fn set_multiline(&mut self, yes: bool) -> &mut Self
pub fn set_multiline(&mut self, yes: bool) -> &mut Self
Ensure all lines for root are indented
Sourcepub fn set_glyphs(&mut self, glyphs: GlyphPalette) -> &mut Self
pub fn set_glyphs(&mut self, glyphs: GlyphPalette) -> &mut Self
Customize the rendering of this node
Source§impl<D: Display, V: Direction> Tree<D, V>
impl<D: Display, V: Direction> Tree<D, V>
Sourcepub fn push(&mut self, leaf: impl Into<Tree<D, V>>) -> &mut Self
pub fn push(&mut self, leaf: impl Into<Tree<D, V>>) -> &mut Self
Examples found in repository?
examples/tree_up.rs (line 16)
10fn tree<P: AsRef<Path>>(p: P) -> io::Result<Tree<String, Up>> {
11 let result = fs::read_dir(&p)?.filter_map(|e| e.ok()).fold(
12 Tree::new(label(p.as_ref().canonicalize()?)),
13 |mut root, entry| {
14 let dir = entry.metadata().unwrap();
15 if dir.is_dir() {
16 root.push(tree(entry.path()).unwrap());
17 } else {
18 root.push(Tree::new(label(entry.path())));
19 }
20 root
21 },
22 );
23 Ok(result)
24}More examples
examples/tree.rs (line 16)
10fn tree<P: AsRef<Path>>(p: P) -> io::Result<Tree<String, Down>> {
11 let result = fs::read_dir(&p)?.filter_map(|e| e.ok()).fold(
12 Tree::new(label(p.as_ref().canonicalize()?)),
13 |mut root, entry| {
14 let dir = entry.metadata().unwrap();
15 if dir.is_dir() {
16 root.push(tree(entry.path()).unwrap());
17 } else {
18 root.push(Tree::new(label(entry.path())));
19 }
20 root
21 },
22 );
23 Ok(result)
24}Trait Implementations§
Source§impl<D: Display, V: Direction> Extend<D> for Tree<D, V>
impl<D: Display, V: Direction> Extend<D> for Tree<D, V>
Source§fn extend<T: IntoIterator<Item = D>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = D>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<D: Display, V: Direction> Extend<Tree<D, V>> for Tree<D, V>
impl<D: Display, V: Direction> Extend<Tree<D, V>> for Tree<D, V>
Source§fn extend<T: IntoIterator<Item = Tree<D, V>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Tree<D, V>>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Auto Trait Implementations§
impl<D, V> Freeze for Tree<D, V>where
D: Freeze,
impl<D, V> RefUnwindSafe for Tree<D, V>where
D: RefUnwindSafe,
V: RefUnwindSafe,
impl<D, V> Send for Tree<D, V>
impl<D, V> Sync for Tree<D, V>
impl<D, V> Unpin for Tree<D, V>
impl<D, V> UnwindSafe for Tree<D, V>where
D: UnwindSafe,
V: 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