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.
Spaces around the section, the name and each attribute are dropped first,
and a blank attribute is left unset: the pantry is matched against recipe
ingredients by name, and milk would never match milk.
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::ReadOnlyConfigif 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::PantryEditif the section or the name is blank, or if the section already holds an item of that name, compared exactly once trimmed. Nothing is written;updateis how an item is changed.CoreError::Configif the existing file cannot be parsed at all, andCoreError::Ioif it cannot be read or the new one cannot be written.