pub struct DocMeta {
pub title: Option<MetaText>,
pub authors: Vec<MetaAuthor>,
pub date: Option<MetaText>,
pub other: BTreeMap<String, Value>,
}Expand description
The document’s metadata: the option type the metadata feature declares, bound
per document (see the module documentation). A program sets its value
on the document (Doc::with_options),
or reads it from data with DocMeta::from_data.
The default holds nothing, and a document whose metadata holds nothing places none of the three pieces.
§Examples
use flm_core::model::doc::{Doc, DocContent};
use flm_core::model::options::OptionValues;
use flm_core::stdlib::features::metadata::{DocMeta, MetaAuthor, MetaText};
let meta = DocMeta::default()
.title(MetaText::new(r"On \emph{flexible} markup"))
.author(MetaAuthor::new(MetaText::new("Ada")).affiliation(MetaText::new("University of X")))
.author(MetaAuthor::new(MetaText::new("Grace")));
let doc = Doc::with_options(DocContent::new(), OptionValues::new().with(meta));Fields§
§title: Option<MetaText>The title.
The authors, in the order written.
date: Option<MetaText>The date, as the author wrote it.
other: BTreeMap<String, Value>Every other key of the metadata, with its value as data. The library does not show these values.
Implementations§
Source§impl DocMeta
impl DocMeta
Sourcepub fn from_data(
data: &Map<String, Value>,
place_of: impl Fn(&MetaPath) -> Option<MetaPlace>,
) -> Result<DocMeta, Vec<MetaDataError>>
pub fn from_data( data: &Map<String, Value>, place_of: impl Fn(&MetaPath) -> Option<MetaPlace>, ) -> Result<DocMeta, Vec<MetaDataError>>
Returns the metadata written as data, a map from a key to its value, in
the form the module documentation states.
place_of returns where each value is written, when the caller knows it;
each text then carries its place, so that a problem in it is reported
there.
§Errors
A MetaDataError, with its path, for each value of title, author and
date, or inside author, that is not of the form stated. An author’s map
whose name is missing or is not a text gives one error, and its other keys
are not read: an error in its affiliation, email or note is reported
only once its name is a text.
§Examples
use flm_core::stdlib::features::metadata::{DocMeta, MetaPlace};
let data = serde_json::json!({
"title": "On \\emph{flexible} markup",
"author": [{"name": "Ada", "affiliation": "University of X"}, "Grace"],
"date": 2026,
"keywords": ["markup"],
});
let meta = DocMeta::from_data(data.as_object().unwrap(), |path| {
Some(MetaPlace::new("paper.flm", if path.key == "title" { 2 } else { 3 }, 8))
})
.unwrap();
assert_eq!(meta.title.unwrap().place.unwrap().line, 2);
assert_eq!(meta.authors.len(), 2);
assert_eq!(meta.authors[0].affiliations[0].text, "University of X");
assert_eq!(meta.date.unwrap().text, "2026");
assert!(meta.other.contains_key("keywords"));Trait Implementations§
impl StructuralPartialEq for DocMeta
Auto Trait Implementations§
impl Forget for DocMeta
impl Freeze for DocMetawhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<MetaAuthor>: Freeze,
*const LeafNode<String, Value> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, Value)>>: Freeze,
impl Move for DocMeta
impl RefUnwindSafe for DocMeta
impl Send for DocMeta
impl Sync for DocMeta
impl Unpin for DocMeta
impl UnsafeUnpin for DocMetawhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<MetaAuthor>: UnsafeUnpin,
*const LeafNode<String, Value> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, Value)>>: UnsafeUnpin,
impl UnwindSafe for DocMeta
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more