pub struct KeyFile { /* private fields */ }Expand description
A parsed key file: an ordered list of groups, each an ordered list of (key, raw value) entries.
Implementations§
Source§impl KeyFile
impl KeyFile
Sourcepub fn get_value(&self, group: &str, key: &str) -> Option<&str>
pub fn get_value(&self, group: &str, key: &str) -> Option<&str>
The raw (still-escaped) value for a key, or None if absent.
Sourcepub fn get_string(&self, group: &str, key: &str) -> Result<Option<String>>
pub fn get_string(&self, group: &str, key: &str) -> Result<Option<String>>
The unescaped string value for a key.
Sourcepub fn get_bool(&self, group: &str, key: &str) -> Result<Option<bool>>
pub fn get_bool(&self, group: &str, key: &str) -> Result<Option<bool>>
A boolean value: one of true, false, 1, or 0, matched exactly.
Sourcepub fn get_integer(&self, group: &str, key: &str) -> Result<Option<i64>>
pub fn get_integer(&self, group: &str, key: &str) -> Result<Option<i64>>
A signed integer value.
Sourcepub fn get_string_list(
&self,
group: &str,
key: &str,
) -> Result<Option<Vec<String>>>
pub fn get_string_list( &self, group: &str, key: &str, ) -> Result<Option<Vec<String>>>
A ;-separated list of unescaped strings. A trailing separator does not
produce a final empty element.
Sourcepub fn set_value(&mut self, group: &str, key: &str, value: &str) -> Result<()>
pub fn set_value(&mut self, group: &str, key: &str, value: &str) -> Result<()>
Set a key’s raw value, creating the group if needed and preserving the position of an existing key.
The group name, key, and value are validated so the serialized form
reparses to an equal KeyFile: a group name may not be empty or
contain [, ], or a newline; a key may not be empty, contain = or
a newline, carry leading or trailing whitespace, or begin with # or
[; a value may not contain a newline or begin with whitespace.
Sourcepub fn set_string(&mut self, group: &str, key: &str, value: &str) -> Result<()>
pub fn set_string(&mut self, group: &str, key: &str, value: &str) -> Result<()>
Set a key to a string value, applying the escaping the tool uses on
write so a value that contains a newline, carriage return, backslash,
or leading whitespace is stored in a form that reparses. This is the
inverse of get_string. Use
set_value to store an already-escaped raw value.
Sourcepub fn remove_key(&mut self, group: &str, key: &str) -> bool
pub fn remove_key(&mut self, group: &str, key: &str) -> bool
Remove one key, reporting whether it was there.
The group stays, even when the removed key was its last: the tool leaves
the header of an emptied group in place, and
Display writes it back with no entries.
Sourcepub fn remove_group(&mut self, group: &str) -> bool
pub fn remove_group(&mut self, group: &str) -> bool
Remove a group and every key in it, reporting whether it was there.
The remaining groups keep their order.
Trait Implementations§
Source§impl Display for KeyFile
Serialize in file order, matching GLib’s layout: a blank line separates
groups, each entry is key=value. Use .to_string() (via Display).
impl Display for KeyFile
Serialize in file order, matching GLib’s layout: a blank line separates
groups, each entry is key=value. Use .to_string() (via Display).