pub struct Forest<T> { /* private fields */ }
Implementations§
Source§impl<T> Forest<T>
impl<T> Forest<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/dirs.rs (line 6)
5fn build_forest(path: &Path) -> Forest<String> {
6 let mut f = Forest::new();
7 if !path.is_dir() {
8 // Ignore files (and anything that's not a directory).
9 return f;
10 }
11 let file_name = path.file_name().unwrap().to_str().unwrap();
12 if file_name.starts_with('.') {
13 // Ignore "hidden" directories.
14 return f;
15 }
16 let mut cur = f.end_mut();
17 // Make current directory the "root" and move cursor to new node.
18 cur.insert_and_move(file_name.to_string());
19 // Set cursor to trailing to append children to it.
20 cur.trailing_of();
21 for entry in path.read_dir().unwrap() {
22 let entry = entry.unwrap();
23 let dir = build_forest(&entry.path());
24 cur.splice(dir);
25 }
26 f
27}
pub fn size(&mut self) -> usize
pub fn size_valid(&self) -> bool
pub fn empty(&self) -> bool
pub fn root(&self) -> Cursor<'_, T>
pub fn root_mut(&mut self) -> CursorMut<'_, T>
Sourcepub fn begin(&self) -> Cursor<'_, T>
pub fn begin(&self) -> Cursor<'_, T>
Examples found in repository?
examples/dirs.rs (line 43)
42fn print(f: &Forest<String>) {
43 let mut cur = f.begin();
44 let mut depth = 0;
45 while cur != f.end() {
46 match (cur.edge(), cur.current().unwrap()) {
47 // Entering directory, print opening tag and increase depth.
48 (Leading, name) => {
49 println!("{}<{}>", Tabs(depth), name);
50 depth += 1;
51 }
52 // Exiting directory, decrease depth and print closing tag.
53 (Trailing, name) => {
54 depth -= 1;
55 println!("{}</{}>", Tabs(depth), name);
56 }
57 }
58 cur.move_next();
59 }
60}
pub fn begin_mut(&mut self) -> CursorMut<'_, T>
Sourcepub fn end(&self) -> Cursor<'_, T>
pub fn end(&self) -> Cursor<'_, T>
Examples found in repository?
examples/dirs.rs (line 45)
42fn print(f: &Forest<String>) {
43 let mut cur = f.begin();
44 let mut depth = 0;
45 while cur != f.end() {
46 match (cur.edge(), cur.current().unwrap()) {
47 // Entering directory, print opening tag and increase depth.
48 (Leading, name) => {
49 println!("{}<{}>", Tabs(depth), name);
50 depth += 1;
51 }
52 // Exiting directory, decrease depth and print closing tag.
53 (Trailing, name) => {
54 depth -= 1;
55 println!("{}</{}>", Tabs(depth), name);
56 }
57 }
58 cur.move_next();
59 }
60}
Sourcepub fn end_mut(&mut self) -> CursorMut<'_, T>
pub fn end_mut(&mut self) -> CursorMut<'_, T>
Examples found in repository?
examples/dirs.rs (line 16)
5fn build_forest(path: &Path) -> Forest<String> {
6 let mut f = Forest::new();
7 if !path.is_dir() {
8 // Ignore files (and anything that's not a directory).
9 return f;
10 }
11 let file_name = path.file_name().unwrap().to_str().unwrap();
12 if file_name.starts_with('.') {
13 // Ignore "hidden" directories.
14 return f;
15 }
16 let mut cur = f.end_mut();
17 // Make current directory the "root" and move cursor to new node.
18 cur.insert_and_move(file_name.to_string());
19 // Set cursor to trailing to append children to it.
20 cur.trailing_of();
21 for entry in path.read_dir().unwrap() {
22 let entry = entry.unwrap();
23 let dir = build_forest(&entry.path());
24 cur.splice(dir);
25 }
26 f
27}
pub fn clear(&mut self)
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Forest<T>
impl<T> RefUnwindSafe for Forest<T>where
T: RefUnwindSafe,
impl<T> !Send for Forest<T>
impl<T> !Sync for Forest<T>
impl<T> Unpin for Forest<T>
impl<T> UnwindSafe for Forest<T>where
T: RefUnwindSafe,
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