pub struct File {
pub path: String,
pub format: FileFormat,
pub content: String,
}Expand description
Representation of a configuration file.
Fields§
§path: String§format: FileFormat§content: StringImplementations§
Source§impl File
impl File
Sourcepub fn new(path: String, format: FileFormat, content: String) -> Self
pub fn new(path: String, format: FileFormat, content: String) -> Self
Create a new file with the given path, format, and content.
Examples found in repository?
examples/saves.rs (line 18)
3fn main() {
4 let default_file = File::new_str("test_file", FileFormat::Json, "{\"key\": \"value\"}");
5 let save = {
6 let mut config = Config::builder()
7 .add_file(default_file.clone())
8 .build()
9 .unwrap();
10 println!("\"key\": {}", config.get("key").unwrap());
11 config.set("key", "another value".into());
12 println!("\"key\" after change: {}", config.get("key").unwrap());
13 config.save(FileFormat::Json).unwrap()
14 };
15
16 let loaded_config = Config::builder()
17 .add_file(default_file.clone())
18 .load(File::new("save.json".to_string(), FileFormat::Json, save))
19 .unwrap()
20 .build()
21 .unwrap();
22 println!("\"key\" after load: {}", loaded_config.get("key").unwrap());
23}Sourcepub fn new_str(path: &str, format: FileFormat, content: &str) -> Self
pub fn new_str(path: &str, format: FileFormat, content: &str) -> Self
Create a new file with the given path, format, and content as a &str.
Examples found in repository?
More examples
examples/changes.rs (lines 5-9)
3fn main() {
4 let mut config = Config::builder()
5 .add_file(File::new_str(
6 "test_file",
7 FileFormat::Json,
8 "{\"key\": \"value\"}",
9 ))
10 .build()
11 .unwrap();
12 println!("\"key\": {}", config.get("key").unwrap());
13 config.set("key", "another value".into());
14 println!("\"key\" after change: {}", config.get("key").unwrap());
15}examples/saves.rs (line 4)
3fn main() {
4 let default_file = File::new_str("test_file", FileFormat::Json, "{\"key\": \"value\"}");
5 let save = {
6 let mut config = Config::builder()
7 .add_file(default_file.clone())
8 .build()
9 .unwrap();
10 println!("\"key\": {}", config.get("key").unwrap());
11 config.set("key", "another value".into());
12 println!("\"key\" after change: {}", config.get("key").unwrap());
13 config.save(FileFormat::Json).unwrap()
14 };
15
16 let loaded_config = Config::builder()
17 .add_file(default_file.clone())
18 .load(File::new("save.json".to_string(), FileFormat::Json, save))
19 .unwrap()
20 .build()
21 .unwrap();
22 println!("\"key\" after load: {}", loaded_config.get("key").unwrap());
23}Trait Implementations§
Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnwindSafe for File
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