pub enum MetaEditor {
Fenced(Embed),
Whole(Editor),
}Expand description
A comment-preserving editor over a document’s metadata, generic over where the metadata lives.
Variants§
Fenced(Embed)
Editing a fenced block inside a host file.
Whole(Editor)
Editing a config document (the whole file is the metadata).
Implementations§
Source§impl MetaEditor
impl MetaEditor
Sourcepub fn open(text: &str, carrier: MetaCarrier) -> Result<Self>
pub fn open(text: &str, carrier: MetaCarrier) -> Result<Self>
Open an editor over text for an existing carrier.
Sourcepub fn open_or_init(text: &str, carrier: Option<MetaCarrier>) -> Result<Self>
pub fn open_or_init(text: &str, carrier: Option<MetaCarrier>) -> Result<Self>
Open an editor over text, creating the metadata block when the
document has none: an explicit carrier is honored (an absent fenced
block is synthesized in place), and None defaults to a fresh
frontmatter block in default_embed_type’s archetype (--- YAML
when that feature is compiled in).
Sourcepub fn set_value(
&mut self,
path: &[Segment<'_>],
value: impl Into<Value>,
) -> Result<()>
pub fn set_value( &mut self, path: &[Segment<'_>], value: impl Into<Value>, ) -> Result<()>
Upsert value at path (the trailing segment must be a key).
Sourcepub fn replace_value(
&mut self,
path: &[Segment<'_>],
value: impl Into<Value>,
) -> Result<()>
pub fn replace_value( &mut self, path: &[Segment<'_>], value: impl Into<Value>, ) -> Result<()>
Replace the existing value at path.
Sourcepub fn replace_key(&mut self, path: &[Segment<'_>], key: &str) -> Result<()>
pub fn replace_key(&mut self, path: &[Segment<'_>], key: &str) -> Result<()>
Rename the key at path, keeping its value, position, and comments.
Sourcepub fn append_value(
&mut self,
path: &[Segment<'_>],
value: impl Into<Value>,
) -> Result<()>
pub fn append_value( &mut self, path: &[Segment<'_>], value: impl Into<Value>, ) -> Result<()>
Append value to the sequence at path.
Sourcepub fn remove_item(&mut self, path: &[Segment<'_>], index: usize) -> Result<()>
pub fn remove_item(&mut self, path: &[Segment<'_>], index: usize) -> Result<()>
Remove the item at index from the sequence at path.
Sourcepub fn reorder_keys<S: AsRef<str>>(
&mut self,
path: &[Segment<'_>],
keys: &[S],
) -> Result<()>
pub fn reorder_keys<S: AsRef<str>>( &mut self, path: &[Segment<'_>], keys: &[S], ) -> Result<()>
Reorder the mapping entries at path (empty path = root) so keys
come first, in that order; entries not listed keep their original
relative order and follow. Unknown keys are ignored. Every entry keeps
its comments and interleaved trivia.
Sourcepub fn reorder_items(
&mut self,
path: &[Segment<'_>],
indices: &[usize],
) -> Result<()>
pub fn reorder_items( &mut self, path: &[Segment<'_>], indices: &[usize], ) -> Result<()>
Reorder the sequence at path so the items at indices (positions in
the current order) come first, in that order; items not listed keep
their original relative order and follow. Out-of-range indices are
ignored.