Struct Settings

Source
pub struct Settings {
    pub readonly: bool,
}
Expand description

Settings for entries in the tree. Currently supports read-only flag, but can be extended with additional settings.

Fields§

§readonly: bool

Whether the file is read-only.

Implementations§

Source§

impl Settings

Source

pub fn new() -> Self

Creates a new Settings with default values.

Examples found in repository?
examples/builder.rs (line 39)
4fn main() {
5    println!("--- Comprehensive TreeBuilder Example ---");
6
7    // 1. Default behavior: creates in a temporary directory, auto-drops
8    let default_tree = TreeBuilder::default()
9        .add_file("default_file.txt", "Content in default temp dir")
10        .create()
11        .expect("Failed to create default tree");
12    println!("Default tree created in: {}", default_tree.root.display());
13    let default_path = default_tree.root.clone();
14    assert!(default_path.exists());
15    drop(default_tree);
16    assert!(
17        !default_path.exists(),
18        "Default tree should be auto-deleted."
19    );
20    println!("Default tree auto-deleted successfully.");
21
22    // 2. Custom root, various file types, and settings
23    let custom_root_path = std::env::temp_dir().join("tree_fs_custom_example");
24    // Clean up previous run if any, for idempotency of example
25    if custom_root_path.exists() {
26        let _ = fs::remove_dir_all(&custom_root_path);
27    }
28
29    let complex_tree = TreeBuilder::default()
30        .root_folder(&custom_root_path) // Custom root
31        .add_file("project/README.md", "# My Project")
32        .add_empty_file("project/.gitignore")
33        .add_directory("project/src")
34        .add_file("project/src/main.rs", "fn main() { println!(\"Hello!\"); }")
35        .add_directory("project/config")
36        .add_file_with_settings(
37            "project/config/prod.json",
38            "{ \"api_key\": \"prod_secret\" }",
39            Settings::new().readonly(true), // Read-only setting
40        )
41        .add_readonly_file("project/config/default.json", "{ \"timeout\": 5000 }")
42        .override_file(true) // Allow overwriting if files exist (e.g. from previous run if not cleaned)
43        .drop(false) // Do not auto-delete this tree
44        .create()
45        .expect("Failed to create complex tree");
46
47    println!("Complex tree created at: {}", complex_tree.root.display());
48    println!("  (This tree will NOT be auto-deleted)");
49
50    // Verify read-only status
51    let readonly_config_path = complex_tree.root.join("project/config/prod.json");
52    match fs::metadata(&readonly_config_path) {
53        Ok(metadata) => {
54            assert!(
55                metadata.permissions().readonly(),
56                "prod.json should be read-only"
57            );
58            println!("Verified: {} is read-only.", readonly_config_path.display());
59        }
60        Err(e) => eprintln!(
61            "Could not get metadata for {}: {}",
62            readonly_config_path.display(),
63            e
64        ),
65    }
66
67    // Verify another readonly file
68    let default_config_path = complex_tree.root.join("project/config/default.json");
69    match fs::metadata(&default_config_path) {
70        Ok(metadata) => {
71            assert!(
72                metadata.permissions().readonly(),
73                "default.json should be read-only"
74            );
75            println!("Verified: {} is read-only.", default_config_path.display());
76        }
77        Err(e) => eprintln!(
78            "Could not get metadata for {}: {}",
79            default_config_path.display(),
80            e
81        ),
82    }
83
84    println!(
85        "Example finished. To clean up, manually delete: {}",
86        custom_root_path.display()
87    );
88}
Source

pub const fn readonly(self, value: bool) -> Self

Sets whether the file is read-only.

Examples found in repository?
examples/builder.rs (line 39)
4fn main() {
5    println!("--- Comprehensive TreeBuilder Example ---");
6
7    // 1. Default behavior: creates in a temporary directory, auto-drops
8    let default_tree = TreeBuilder::default()
9        .add_file("default_file.txt", "Content in default temp dir")
10        .create()
11        .expect("Failed to create default tree");
12    println!("Default tree created in: {}", default_tree.root.display());
13    let default_path = default_tree.root.clone();
14    assert!(default_path.exists());
15    drop(default_tree);
16    assert!(
17        !default_path.exists(),
18        "Default tree should be auto-deleted."
19    );
20    println!("Default tree auto-deleted successfully.");
21
22    // 2. Custom root, various file types, and settings
23    let custom_root_path = std::env::temp_dir().join("tree_fs_custom_example");
24    // Clean up previous run if any, for idempotency of example
25    if custom_root_path.exists() {
26        let _ = fs::remove_dir_all(&custom_root_path);
27    }
28
29    let complex_tree = TreeBuilder::default()
30        .root_folder(&custom_root_path) // Custom root
31        .add_file("project/README.md", "# My Project")
32        .add_empty_file("project/.gitignore")
33        .add_directory("project/src")
34        .add_file("project/src/main.rs", "fn main() { println!(\"Hello!\"); }")
35        .add_directory("project/config")
36        .add_file_with_settings(
37            "project/config/prod.json",
38            "{ \"api_key\": \"prod_secret\" }",
39            Settings::new().readonly(true), // Read-only setting
40        )
41        .add_readonly_file("project/config/default.json", "{ \"timeout\": 5000 }")
42        .override_file(true) // Allow overwriting if files exist (e.g. from previous run if not cleaned)
43        .drop(false) // Do not auto-delete this tree
44        .create()
45        .expect("Failed to create complex tree");
46
47    println!("Complex tree created at: {}", complex_tree.root.display());
48    println!("  (This tree will NOT be auto-deleted)");
49
50    // Verify read-only status
51    let readonly_config_path = complex_tree.root.join("project/config/prod.json");
52    match fs::metadata(&readonly_config_path) {
53        Ok(metadata) => {
54            assert!(
55                metadata.permissions().readonly(),
56                "prod.json should be read-only"
57            );
58            println!("Verified: {} is read-only.", readonly_config_path.display());
59        }
60        Err(e) => eprintln!(
61            "Could not get metadata for {}: {}",
62            readonly_config_path.display(),
63            e
64        ),
65    }
66
67    // Verify another readonly file
68    let default_config_path = complex_tree.root.join("project/config/default.json");
69    match fs::metadata(&default_config_path) {
70        Ok(metadata) => {
71            assert!(
72                metadata.permissions().readonly(),
73                "default.json should be read-only"
74            );
75            println!("Verified: {} is read-only.", default_config_path.display());
76        }
77        Err(e) => eprintln!(
78            "Could not get metadata for {}: {}",
79            default_config_path.display(),
80            e
81        ),
82    }
83
84    println!(
85        "Example finished. To clean up, manually delete: {}",
86        custom_root_path.display()
87    );
88}

Trait Implementations§

Source§

impl Clone for Settings

Source§

fn clone(&self) -> Settings

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Settings

Source§

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

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

impl Default for Settings

Source§

fn default() -> Settings

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Settings

Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Settings

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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>,