Skip to main content

add

Function add 

Source
pub fn add(
    ctx: &Context,
    req: AddRequest,
) -> Result<Outcome<PantryContents>, CoreError>
Expand description

Add an item to the pantry and write it back.

The section is created if the file has no such section, and the file itself is created if there is none — under <base_path>/config/pantry.conf, which is where Context::discover looks first. That is the one case where this crate invents a path rather than being told one.

Returns the pantry as it now stands on disk, so a caller need not read it back, together with any warnings from parsing what was there before.

Only the entry asked for is touched; see what a write touches.

§Errors

  • CoreError::ReadOnlyConfig if the context carries the pantry inline. There is nowhere to write it, and inventing a path would put an editor’s unsaved buffer on someone’s disk.
  • CoreError::PantryEdit if the section already holds an item of that name, compared exactly. Nothing is written; update is how an item is changed.
  • CoreError::Config if the existing file cannot be parsed at all, and CoreError::Io if it cannot be read or the new one cannot be written.