roezio/config: move set method alongside get
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
b7bfa835c9
commit
1575e7c8aa
1 changed files with 15 additions and 15 deletions
|
@ -158,21 +158,6 @@ impl<'a> Config<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets a key/value pair in memory and updates the config file.
|
|
||||||
pub(crate) fn set(
|
|
||||||
&mut self,
|
|
||||||
key: &str,
|
|
||||||
value: ConfigValue,
|
|
||||||
section: Option<Jid>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let section: String = section
|
|
||||||
.map(|jid| jid.to_string())
|
|
||||||
.unwrap_or(String::from("default"));
|
|
||||||
self.write_to_file(key.clone(), value.clone(), section.as_str())?;
|
|
||||||
let _ = self.ini.set(section.as_str(), key, Some(value.to_string()));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse<R: Read + BufRead>(
|
fn parse<R: Read + BufRead>(
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
key: String,
|
key: String,
|
||||||
|
@ -300,6 +285,21 @@ impl<'a> Config<'a> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets a key/value pair in memory and updates the config file.
|
||||||
|
pub(crate) fn set(
|
||||||
|
&mut self,
|
||||||
|
key: &str,
|
||||||
|
value: ConfigValue,
|
||||||
|
section: Option<Jid>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let section: String = section
|
||||||
|
.map(|jid| jid.to_string())
|
||||||
|
.unwrap_or(String::from("default"));
|
||||||
|
self.write_to_file(key.clone(), value.clone(), section.as_str())?;
|
||||||
|
let _ = self.ini.set(section.as_str(), key, Some(value.to_string()));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Fetches a value
|
/// Fetches a value
|
||||||
pub(crate) fn get(
|
pub(crate) fn get(
|
||||||
&self,
|
&self,
|
||||||
|
|
Loading…
Reference in a new issue