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
impl TreeBuilder
Sourcepub fn root_folder<P: AsRef<Path>>(self, dir: P) -> Self
pub fn root_folder<P: AsRef<Path>>(self, dir: P) -> Self
Sets the root folder where the tree will be created.
Sourcepub const fn drop(self, yes: bool) -> Self
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());
}
Sourcepub const fn override_file(self, yes: bool) -> Self
pub const fn override_file(self, yes: bool) -> Self
Sets the override_file
flag, indicating whether existing files should be overridden.
Sourcepub fn add<P: AsRef<Path>>(self, path: P, content: &str) -> Self
pub fn add<P: AsRef<Path>>(self, path: P, content: &str) -> Self
Adds a file with content to the tree.
Examples found in repository?
More 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());
}
Sourcepub fn add_empty<P: AsRef<Path>>(self, path: P) -> Self
pub fn add_empty<P: AsRef<Path>>(self, path: P) -> Self
Adds a file with a empty content.
Examples found in repository?
More 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());
}
Sourcepub fn create(&self) -> Result<Tree>
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?
More 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
impl Debug for TreeBuilder
Source§impl Default for TreeBuilder
impl Default for TreeBuilder
Source§impl<'de> Deserialize<'de> for TreeBuilder
impl<'de> Deserialize<'de> for TreeBuilder
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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§
impl Freeze for TreeBuilder
impl RefUnwindSafe for TreeBuilder
impl Send for TreeBuilder
impl Sync for TreeBuilder
impl Unpin for TreeBuilder
impl UnwindSafe for TreeBuilder
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