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
impl Settings
Sourcepub fn new() -> Self
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}
Sourcepub const fn readonly(self, value: bool) -> Self
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<'de> Deserialize<'de> for Settings
impl<'de> Deserialize<'de> for Settings
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 Settings
impl RefUnwindSafe for Settings
impl Send for Settings
impl Sync for Settings
impl Unpin for Settings
impl UnwindSafe for Settings
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