Skip to main content

KeyFile

Struct KeyFile 

Source
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

Source

pub fn parse(input: &str) -> Result<KeyFile>

Parse a key file from text.

Source

pub fn has_group(&self, group: &str) -> bool

Whether a group is present.

Source

pub fn groups(&self) -> impl Iterator<Item = &str>

Iterate group names in file order.

Source

pub fn get_value(&self, group: &str, key: &str) -> Option<&str>

The raw (still-escaped) value for a key, or None if absent.

Source

pub fn get_string(&self, group: &str, key: &str) -> Result<Option<String>>

The unescaped string value for a key.

Source

pub fn get_bool(&self, group: &str, key: &str) -> Result<Option<bool>>

A boolean value: one of true, false, 1, or 0, matched exactly.

Source

pub fn get_integer(&self, group: &str, key: &str) -> Result<Option<i64>>

A signed integer value.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 Clone for KeyFile

Source§

fn clone(&self) -> KeyFile

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KeyFile

Source§

fn default() -> KeyFile

Returns the “default value” for a type. Read more
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).

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for KeyFile

Source§

impl PartialEq for KeyFile

Source§

fn eq(&self, other: &KeyFile) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for KeyFile

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.