Struct gray_matter::Matter
source · [−]pub struct Matter<T: Engine> {
pub delimiter: String,
pub excerpt_delimiter: Option<String>,
/* private fields */
}
Expand description
Coupled with an Engine
of choice, Matter
stores delimiter(s) and
handles parsing.
Fields
delimiter: String
excerpt_delimiter: Option<String>
Implementations
sourceimpl<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");
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Matter<T> where
T: RefUnwindSafe,
impl<T> Send for Matter<T> where
T: Send,
impl<T> Sync for Matter<T> where
T: Sync,
impl<T> Unpin for Matter<T> where
T: Unpin,
impl<T> UnwindSafe for Matter<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more