tree_fs

Struct TreeBuilder

Source
pub struct TreeBuilder {
    pub root: PathBuf,
    /* private fields */
}
Expand description

Represents a file tree structure

§Examples

use tree_fs::TreeBuilder;
let tree_fs = TreeBuilder::default()
    .add("test/foo.txt", "bar")
    .add_empty("test/folder-a/folder-b/bar.txt")
    .create()
    .expect("create tree fs");
println!("created successfully in {}", tree_fs.root.display());
use tree_fs::TreeBuilder;
let tree_fs = TreeBuilder::default()
     .add("test/foo.txt", "bar")
     .add_empty("test/folder-a/folder-b/bar.txt")
     .drop(true)
     .create()
     .expect("create tree fs");

println!("created successfully in {}", tree_fs.root.display());

let path = tree_fs.root.clone();
assert!(path.exists());

drop(tree_fs);
assert!(!path.exists());

Fields§

§root: PathBuf

Root folder where the tree will be created.

Implementations§

Source§

impl TreeBuilder

Source

pub fn root_folder<P: AsRef<Path>>(self, dir: P) -> Self

Sets the root folder where the tree will be created.

Source

pub const fn drop(self, yes: bool) -> Self

Sets the override_file flag, indicating whether existing files should be overridden.

Examples found in repository?
examples/drop.rs (line 7)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let tree_fs = TreeBuilder::default()
        .add("test/foo.txt", "bar")
        .add_empty("test/folder-a/folder-b/bar.txt")
        .drop(true)
        .create()
        .expect("create tree fs");

    println!("created successfully in {}", tree_fs.root.display());

    let path = tree_fs.root.clone();
    assert!(path.exists());

    drop(tree_fs);
    assert!(!path.exists());
}
Source

pub const fn override_file(self, yes: bool) -> Self

Sets the override_file flag, indicating whether existing files should be overridden.

Source

pub fn add<P: AsRef<Path>>(self, path: P, content: &str) -> Self

Adds a file with content to the tree.

Examples found in repository?
examples/builder.rs (line 5)
3
4
5
6
7
8
9
10
11
fn main() {
    let tree_fs = TreeBuilder::default()
        .add("test/foo.txt", "bar")
        .add_empty("test/folder-a/folder-b/bar.txt")
        .create()
        .expect("create tree fs");

    println!("created successfully in {}", tree_fs.root.display());
}
More examples
Hide additional examples
examples/drop.rs (line 5)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let tree_fs = TreeBuilder::default()
        .add("test/foo.txt", "bar")
        .add_empty("test/folder-a/folder-b/bar.txt")
        .drop(true)
        .create()
        .expect("create tree fs");

    println!("created successfully in {}", tree_fs.root.display());

    let path = tree_fs.root.clone();
    assert!(path.exists());

    drop(tree_fs);
    assert!(!path.exists());
}
Source

pub fn add_empty<P: AsRef<Path>>(self, path: P) -> Self

Adds a file with a empty content.

Examples found in repository?
examples/builder.rs (line 6)
3
4
5
6
7
8
9
10
11
fn main() {
    let tree_fs = TreeBuilder::default()
        .add("test/foo.txt", "bar")
        .add_empty("test/folder-a/folder-b/bar.txt")
        .create()
        .expect("create tree fs");

    println!("created successfully in {}", tree_fs.root.display());
}
More examples
Hide additional examples
examples/drop.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let tree_fs = TreeBuilder::default()
        .add("test/foo.txt", "bar")
        .add_empty("test/folder-a/folder-b/bar.txt")
        .drop(true)
        .create()
        .expect("create tree fs");

    println!("created successfully in {}", tree_fs.root.display());

    let path = tree_fs.root.clone();
    assert!(path.exists());

    drop(tree_fs);
    assert!(!path.exists());
}
Source

pub fn create(&self) -> Result<Tree>

Creates the file tree by generating files and directories based on the specified metadata.

§Errors

Returns an std::io::Result indicating success or failure in creating the file tree.

Examples found in repository?
examples/builder.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let tree_fs = TreeBuilder::default()
        .add("test/foo.txt", "bar")
        .add_empty("test/folder-a/folder-b/bar.txt")
        .create()
        .expect("create tree fs");

    println!("created successfully in {}", tree_fs.root.display());
}
More examples
Hide additional examples
examples/drop.rs (line 8)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let tree_fs = TreeBuilder::default()
        .add("test/foo.txt", "bar")
        .add_empty("test/folder-a/folder-b/bar.txt")
        .drop(true)
        .create()
        .expect("create tree fs");

    println!("created successfully in {}", tree_fs.root.display());

    let path = tree_fs.root.clone();
    assert!(path.exists());

    drop(tree_fs);
    assert!(!path.exists());
}

Trait Implementations§

Source§

impl Debug for TreeBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TreeBuilder

Source§

fn default() -> Self

Creates a default Tree instance with an empty file list,

Source§

impl<'de> Deserialize<'de> for TreeBuilder

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,