pub struct Leaf { /* private fields */ }Expand description
A single metadata fence parsed from a Quillmark Markdown document.
A Leaf is the uniform shape for both the document entry (main) fence and
composable leaf fences. sentinel distinguishes the two.
Every leaf has:
sentinel— theQUILLreference (for main) orKINDtag (for composable).frontmatter— ordered items parsed from the YAML fence body (with the sentinel key already removed).body— the Markdown text that follows the closing fence, up to the next fence (or EOF).
§Leaf body absence
If a leaf block has no trailing Markdown content (e.g. the next block or
EOF immediately follows the closing fence), body is the empty string "".
It is never None; callers that need to distinguish “absent” from “empty”
should check leaf.body().is_empty().
Implementations§
Source§impl Leaf
impl Leaf
Sourcepub fn new(tag: impl Into<String>) -> Result<Self, EditError>
pub fn new(tag: impl Into<String>) -> Result<Self, EditError>
Create a new, empty composable leaf with the given tag.
§Invariants enforced
tag must match [a-z_][a-z0-9_]*. An invalid tag returns
EditError::InvalidTagName.
The new leaf has no fields and an empty body.
Sourcepub fn set_field(
&mut self,
name: &str,
value: QuillValue,
) -> Result<(), EditError>
pub fn set_field( &mut self, name: &str, value: QuillValue, ) -> Result<(), EditError>
Set a frontmatter field by name. Always clears the !fill marker for
that key — the “user filled in” path.
§Invariants enforced
namemust not be one of the reserved sentinel names. ReturnsEditError::ReservedName.namemust match[a-z_][a-z0-9_]*after NFC normalisation. ReturnsEditError::InvalidFieldName.
§Validity
After a successful call the leaf remains valid: frontmatter
contains no reserved key and the value is stored at the correct key.
§Warnings
Leaf mutators never modify the parent document’s warnings.
Sourcepub fn set_fill(
&mut self,
name: &str,
value: QuillValue,
) -> Result<(), EditError>
pub fn set_fill( &mut self, name: &str, value: QuillValue, ) -> Result<(), EditError>
Set a frontmatter field AND mark it as a !fill placeholder — the
“reset to placeholder” path. A Null value emits as key: !fill;
a scalar or sequence value emits as key: !fill <value>.
§Invariants enforced
Same as Leaf::set_field.
§Warnings
Leaf mutators never modify the parent document’s warnings.
Sourcepub fn remove_field(
&mut self,
name: &str,
) -> Result<Option<QuillValue>, EditError>
pub fn remove_field( &mut self, name: &str, ) -> Result<Option<QuillValue>, EditError>
Remove a frontmatter field by name, returning the value if it existed.
§Invariants enforced
namemust not be one of the reserved sentinel names. ReturnsEditError::ReservedName.namemust match[a-z_][a-z0-9_]*after NFC normalisation. ReturnsEditError::InvalidFieldName.
Absence of an otherwise-valid name returns Ok(None).
§Warnings
Leaf mutators never modify the parent document’s warnings.
Sourcepub fn replace_body(&mut self, body: impl Into<String>)
pub fn replace_body(&mut self, body: impl Into<String>)
Replace the leaf’s Markdown body.
§Warnings
Leaf mutators never modify the parent document’s warnings.
Source§impl Leaf
impl Leaf
Sourcepub fn new_with_sentinel(
sentinel: Sentinel,
frontmatter: Frontmatter,
body: String,
) -> Self
pub fn new_with_sentinel( sentinel: Sentinel, frontmatter: Frontmatter, body: String, ) -> Self
Create a Leaf directly from a sentinel, a typed frontmatter, and a
body. Does not validate the sentinel tag or any field names —
callers are responsible for providing already-valid data. For
user-facing construction of composable leaves use Leaf::new
(defined in edit.rs).
Sourcepub fn sentinel(&self) -> &Sentinel
pub fn sentinel(&self) -> &Sentinel
The sentinel discriminating this leaf as main or composable.
Sourcepub fn tag(&self) -> String
pub fn tag(&self) -> String
The leaf tag — the KIND: value for composable leaves, or the string
form of the quill reference for main leaves.
Sourcepub fn frontmatter(&self) -> &Frontmatter
pub fn frontmatter(&self) -> &Frontmatter
Typed frontmatter (map-keyed view and ordered item list).
Sourcepub fn frontmatter_mut(&mut self) -> &mut Frontmatter
pub fn frontmatter_mut(&mut self) -> &mut Frontmatter
Mutable access to the frontmatter.