Forest

Struct Forest 

Source
pub struct Forest<T> { /* private fields */ }

Implementations§

Source§

impl<T> Forest<T>

Source

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}
Source

pub fn size(&mut self) -> usize

Source

pub fn size_valid(&self) -> bool

Source

pub fn empty(&self) -> bool

Source

pub fn root(&self) -> Cursor<'_, T>

Source

pub fn root_mut(&mut self) -> CursorMut<'_, T>

Source

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}
Source

pub fn begin_mut(&mut self) -> CursorMut<'_, T>

Source

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}
Source

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}
Source

pub fn clear(&mut self)

Trait Implementations§

Source§

impl<T> Drop for Forest<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.