pub struct Tree<D: Display> {
pub root: D,
pub leaves: Vec<Tree<D>>,
/* 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>>
Implementations§
source§impl<D: Display> Tree<D>
impl<D: Display> Tree<D>
sourcepub fn new(root: D) -> Self
pub fn new(root: D) -> Self
Examples found in repository?
examples/tree.rs (line 12)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn tree<P: AsRef<Path>>(p: P) -> io::Result<Tree<String>> {
let result = fs::read_dir(&p)?.filter_map(|e| e.ok()).fold(
Tree::new(label(p.as_ref().canonicalize()?)),
|mut root, entry| {
let dir = entry.metadata().unwrap();
if dir.is_dir() {
root.push(tree(entry.path()).unwrap());
} else {
root.push(Tree::new(label(entry.path())));
}
root
},
);
Ok(result)
}
pub fn with_leaves( self, leaves: impl IntoIterator<Item = impl Into<Tree<D>>> ) -> 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> Tree<D>
impl<D: Display> Tree<D>
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> Tree<D>
impl<D: Display> Tree<D>
sourcepub fn push(&mut self, leaf: impl Into<Tree<D>>) -> &mut Self
pub fn push(&mut self, leaf: impl Into<Tree<D>>) -> &mut Self
Examples found in repository?
examples/tree.rs (line 16)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn tree<P: AsRef<Path>>(p: P) -> io::Result<Tree<String>> {
let result = fs::read_dir(&p)?.filter_map(|e| e.ok()).fold(
Tree::new(label(p.as_ref().canonicalize()?)),
|mut root, entry| {
let dir = entry.metadata().unwrap();
if dir.is_dir() {
root.push(tree(entry.path()).unwrap());
} else {
root.push(Tree::new(label(entry.path())));
}
root
},
);
Ok(result)
}
Trait Implementations§
source§impl<D: Display> Extend<D> for Tree<D>
impl<D: Display> Extend<D> for Tree<D>
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> Extend<Tree<D>> for Tree<D>
impl<D: Display> Extend<Tree<D>> for Tree<D>
source§fn extend<T: IntoIterator<Item = Tree<D>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Tree<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