Skip to main content

ConfigEdit

Struct ConfigEdit 

Source
pub struct ConfigEdit<'a> { /* private fields */ }
Expand description

An edit of the document of config.

The edit changes the document in memory. It does no file I/O. Each write stores the text of Value::format, and the other keys and groups keep their order and their text. A write takes each key of a single group, also a key that is not Settable.

ConfigEdit::new gives an edit of a key file. In the ostrya crate, UpdateGuard::edit_config gives an edit of the document of config, and writes the edited document.

Implementations§

Source§

impl<'a> ConfigEdit<'a>

Source

pub fn new(keyfile: &'a mut KeyFile) -> ConfigEdit<'a>

Returns an edit of keyfile.

§Examples
use ostrya_core::KeyFile;
use ostrya_core::config::{ConfigEdit, ConfigError, ConfigView, repo};

let mut kf = KeyFile::parse("[core]\nrepo_version=1\nmode=bare\n")?;
ConfigEdit::new(&mut kf).set::<repo::Fsync>(false)?;
assert_eq!(kf.get_value("core", "fsync"), Some("false"));
assert!(!ConfigView::new(&kf).get::<repo::Fsync>()?);
Source

pub fn set<K>(&mut self, value: ValueOf<K>) -> Result<(), ConfigError>
where K: SingleKey + Key<<K as SingleKey>::Group>,

Sets the key K of a single group to value.

If the key is present, the new value replaces the old value at the same position. If the key is absent, the call adds it at the end of its group. If the group is absent, the call adds it at the end of the document.

§Errors

ConfigError::Core if the text of the value cannot be in a key file, for example a text with a line break. The document then does not change.

Source

pub fn remove<K>(&mut self) -> bool
where K: SingleKey + Key<<K as SingleKey>::Group>,

Removes the key K of a single group, and returns true if the key was present.

The group stays, also when it loses its last key.

Source

pub fn section_mut<G: Group>( &mut self, name: &str, ) -> Result<SectionMut<'_, G>, ConfigError>

Returns the edit of the section name of the named group G.

The call does not add the section. The first set adds it at the end of the document.

§Errors

ConfigError::InvalidInput if name is empty, or holds [, ], ", or a line break. A key file cannot hold such a group header, and a read of a section does not take such a name.

Source

pub fn remove_section<G: Group>(&mut self, name: &str) -> bool

Removes the section name of the named group G with its keys, and returns true if the section was present.

Source

pub fn keyfile_mut(&mut self) -> &mut KeyFile

Returns the document, for an edit that the typed writes do not cover.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for ConfigEdit<'a>

§

impl<'a> Forget for ConfigEdit<'a>

§

impl<'a> Freeze for ConfigEdit<'a>
where &'a mut KeyFile: Freeze,

§

impl<'a> Move for ConfigEdit<'a>

§

impl<'a> RefUnwindSafe for ConfigEdit<'a>

§

impl<'a> Send for ConfigEdit<'a>
where RawVecInner: Send, RawTable<(String, usize)>: Send,

§

impl<'a> Sync for ConfigEdit<'a>
where RawVecInner: Sync, RawTable<(String, usize)>: Sync,

§

impl<'a> Unpin for ConfigEdit<'a>
where &'a mut KeyFile: Unpin,

§

impl<'a> UnsafeUnpin for ConfigEdit<'a>
where &'a mut KeyFile: UnsafeUnpin,

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> 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, 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.