pub struct Card { /* private fields */ }Expand description
A single metadata fence parsed from a Quillmark Markdown document.
A Card is the uniform shape for both the document entry (main) fence and
composable card fences. sentinel distinguishes the two.
Every card has:
sentinel— theQUILLreference (for main) orCARDtag (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).
§Card body absence
If a card 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 card.body().is_empty().
Implementations§
Source§impl Card
impl Card
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 card with the given tag.
§Invariants enforced
tag must match [a-z_][a-z0-9_]*. An invalid tag returns
EditError::InvalidTagName.
The new card 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 card remains valid: frontmatter
contains no reserved key and the value is stored at the correct key.
§Warnings
Card 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 Card::set_field.
§Warnings
Card 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
Card 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 card’s Markdown body.
§Warnings
Card mutators never modify the parent document’s warnings.
Source§impl Card
impl Card
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 Card 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 cards use Card::new
(defined in edit.rs).
Sourcepub fn sentinel(&self) -> &Sentinel
pub fn sentinel(&self) -> &Sentinel
The sentinel discriminating this card as main or composable.
Sourcepub fn tag(&self) -> String
pub fn tag(&self) -> String
The card tag — the CARD: value for composable cards, or the string
form of the quill reference for main cards.
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.