roezio/config: move set method alongside get

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-08-30 15:33:22 +02:00
parent b7bfa835c9
commit 1575e7c8aa

View file

@ -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>(
mut reader: R,
key: String,
@ -300,6 +285,21 @@ impl<'a> Config<'a> {
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
pub(crate) fn get(
&self,