Struct gray_matter::Matter
source · pub struct Matter<T: Engine> { /* private fields */ }
Expand description
Coupled with an Engine
of choice, Matter
stores delimiter(s) and
handles parsing.
Implementations§
source§impl<T: Engine> Matter<T>
impl<T: Engine> Matter<T>
pub fn new() -> Self
sourcepub fn parse(&self, input: &str) -> ParsedEntity
pub fn parse(&self, input: &str) -> ParsedEntity
Runs parsing on the input. Uses the engine contained in self
to parse any front matter
detected.
Examples
Basic usage:
let matter: Matter<YAML> = Matter::new();
let input = "---\ntitle: Home\n---\nOther stuff";
let parsed_entity = matter.parse(input);
assert_eq!(parsed_entity.content, "Other stuff");
sourcepub fn parse_with_struct<D: DeserializeOwned>(
&self,
input: &str
) -> Option<ParsedEntityStruct<D>>
pub fn parse_with_struct<D: DeserializeOwned>( &self, input: &str ) -> Option<ParsedEntityStruct<D>>
Wrapper around parse
, that deserializes any front matter into a custom
struct. Supplied as an ease-of-use function to prevent having to deserialize manually.
Returns None
if no front matter is found, or if the front matter is not deserializable
into the custom struct.
Examples
Basic usage:
#[derive(serde::Deserialize)]
struct Config {
title: String,
}
let matter: Matter<YAML> = Matter::new();
let input = "---\ntitle: Home\n---\nOther stuff";
let parsed_entity = matter.parse_with_struct::<Config>(input).unwrap();
assert_eq!(parsed_entity.data.title, "Home");