Skip to main content

Module edit

Module edit 

Source
Expand description

Format-preserving edits to a document’s metadata, whatever carries it.

MetaEditor dispatches on the document’s MetaCarrier: a fenced block is edited with fig’s fig::Embed (fences and body untouched), a config document with fig’s fig::Editor (the whole file is the metadata). Either way the edit is comment-preserving and byte-minimal — only the changed node’s bytes move — and the original carrier and format are never rewritten into another.

The workspace mutation ops build on this; the free functions are the single-document surface (the CLI’s set/unset).

Enums§

MetaEditor
A comment-preserving editor over a document’s metadata, generic over where the metadata lives.

Functions§

infer_scalar
Interpret a CLI-provided scalar: true/false, integers, floats, and null become their typed values; everything else stays a string.
key_path
Parse a dotted key path (a.b.0.c) into fig path segments. An all-digit segment indexes a sequence; anything else names a mapping key.
reformat_block
Re-emit mapping as a fresh metadata block of archetype target, placed in target’s canonical position around the plain body (before it for frontmatter, after it for endmatter) — the reconstruction a format conversion performs. Unlike the comment-preserving edits above, this deliberately rebuilds the block: a conversion crosses formats (a YAML comment has no JSON home), so only the values survive.
set_in_text
Upsert dotted to value in text’s metadata (carrier-aware), creating a YAML frontmatter block when the document has none. Returns the full re-rendered document text.
set_meta_in_text
Upsert dotted to a full Value — the mapping-valued counterpart to set_in_text, which takes only a fig::Value scalar. Lets a caller set a whole nested block (e.g. the root’s prov: policy block) without naming fig, converting through the crate’s Value → fig::Value bridge.
unset_in_text
Delete the entry at dotted from text’s metadata (carrier-aware). Returns the full re-rendered document text. Errors when the document has no metadata or the path does not exist.