Skip to main content

MetaEditor

Enum MetaEditor 

Source
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

Source

pub fn open(text: &str, carrier: MetaCarrier) -> Result<Self>

Open an editor over text for an existing carrier.

Source

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

Source

pub fn set_value( &mut self, path: &[Segment<'_>], value: impl Into<Value>, ) -> Result<()>

Upsert value at path (the trailing segment must be a key).

Source

pub fn replace_value( &mut self, path: &[Segment<'_>], value: impl Into<Value>, ) -> Result<()>

Replace the existing value at path.

Source

pub fn replace_key(&mut self, path: &[Segment<'_>], key: &str) -> Result<()>

Rename the key at path, keeping its value, position, and comments.

Source

pub fn append_value( &mut self, path: &[Segment<'_>], value: impl Into<Value>, ) -> Result<()>

Append value to the sequence at path.

Source

pub fn delete(&mut self, path: &[Segment<'_>]) -> Result<()>

Delete the mapping entry at path.

Source

pub fn remove_item(&mut self, path: &[Segment<'_>], index: usize) -> Result<()>

Remove the item at index from the sequence at path.

Source

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.

Source

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.

Source

pub fn render(&mut self) -> Result<String>

Render the full document text with the edits applied.

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.