pub struct Config {
pub path: PathBuf,
/* private fields */
}
Fields§
§path: PathBuf
Implementations§
Source§impl Config
impl Config
Sourcepub fn new<T: AsRef<str>>(name: T) -> Result<Self>
pub fn new<T: AsRef<str>>(name: T) -> Result<Self>
Create a new system config.
Examples found in repository?
More examples
examples/multiple.rs (line 12)
11fn write() {
12 let mut config = Config::new("system-config-multiple-example").unwrap();
13
14 config.write_insert("1", "value 1").unwrap();
15 config.write_insert("2", "value 2").unwrap();
16 config.write_insert("3", "value 3").unwrap();
17
18 println!("wrote:\n 1 value 1\n 2 value 2\n 3 value 3\n");
19}
20
21fn read() {
22 let mut config = Config::new("system-config-multiple-example").unwrap();
23
24 let x1 = config.read_get("1").unwrap().unwrap();
25 let x2 = config.read_get("2").unwrap().unwrap();
26 let x3 = config.read_get("3").unwrap().unwrap();
27
28 println!("read:\n 1 {}\n 2 {}\n 3 {}\n", x1, x2, x3);
29}
Sourcepub fn write_clear_by_name<T: AsRef<str>>(name: T) -> Result<()>
pub fn write_clear_by_name<T: AsRef<str>>(name: T) -> Result<()>
Clear a config by name and sync it with the disk.
Sourcepub fn insert<T: AsRef<str>>(&mut self, key: T, value: T)
pub fn insert<T: AsRef<str>>(&mut self, key: T, value: T)
Insert a key-value pair into the config.
Sourcepub fn write_insert<T: AsRef<str>>(&mut self, key: T, value: T) -> Result<()>
pub fn write_insert<T: AsRef<str>>(&mut self, key: T, value: T) -> Result<()>
Insert a key-value pair into the config and write to disk.
Sourcepub fn read_get<T: AsRef<str>>(&mut self, query: T) -> Result<Option<String>>
pub fn read_get<T: AsRef<str>>(&mut self, query: T) -> Result<Option<String>>
Read the system config and get a value for a key.
Sourcepub fn write_clear(&mut self) -> Result<()>
pub fn write_clear(&mut self) -> Result<()>
Clear all data in the config and write to disk.
Trait Implementations§
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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