diff --git a/src/frontmatter.rs b/src/frontmatter.rs index 5816eb0..326d4ac 100644 --- a/src/frontmatter.rs +++ b/src/frontmatter.rs @@ -12,6 +12,18 @@ pub struct FrontMatter { pub data: Option, } +impl FrontMatter { + /// Creates a new front matter. + pub fn new(data: Option, content: String) -> Self { + Self { data, content } + } + + /// Creates a new front matter without content. + pub fn new_empty(data: Option) -> Self { + Self::new(data, String::new()) + } +} + impl FrontMatter where T: DeserializeOwned, @@ -63,6 +75,16 @@ where pub struct FrontMatterRequired(FrontMatter); impl FrontMatterRequired { + /// Creates a new front matter. + pub fn new(data: T, content: String) -> Self { + Self(FrontMatter::new(Some(data), content)) + } + + /// Creates a new front matter without content. + pub fn new_empty(data: T) -> Self { + Self(FrontMatter::new_empty(Some(data))) + } + /// Gets a reference to the front matter's data. pub fn data(&self) -> &T { self.0.data.as_ref().expect("missing front matter data")