Struct extract_frontmatter::Extractor
source · [−]pub struct Extractor<'opt> { /* private fields */ }Expand description
Holds configuration for how front-matter and data should be extracted from a string.
- Instantiate using
Extractor::new()with the desiredSplitter - (Optional) Call
.with_modifier()with a desiredModifier; repeat as necessary - Call
.extract()with a string to get back a tuple of front-matter and data
Usage
Example 1 (Markdown with TOML)
Input:
[meta]
field_one = 10
field_two = [2, 4]
+++
# Markdown example
This is an example markdown document that contains the following TOML front-matter:
[meta]
field_one = 10
field_two = [2, 4]Code:
let (front_matter, data) = Extractor::new(Splitter::DelimiterLine("+++")).extract(input);Front-matter output:
[meta]
field_one = 10
field_two = [2, 4]Data output:
# Markdown example
This is an example markdown document that contains the following TOML front-matter:
[meta]
field_one = 10
field_two = [2, 4]Example 2 (SQL with YAML)
Input:
-- meta:
-- field_one: 10
-- field_two:
-- - 2
-- - 4
SELECT version();Code:
let (front_matter, data) = Extractor::new(Splitter::LinePrefix("-- "))
.with_modifier(Modifier::StripPrefix("-- "))
.extract(input);Front-matter output:
meta:
field_one: 10
field_two:
- 2
- 4Data output:
SELECT version();Implementations
sourceimpl<'opt> Extractor<'opt>
impl<'opt> Extractor<'opt>
sourcepub fn with_modifier(&mut self, modifier: Modifier<'opt>) -> &mut Self
pub fn with_modifier(&mut self, modifier: Modifier<'opt>) -> &mut Self
Add a modifier to the front-matter returned by .extract().
Trait Implementations
Auto Trait Implementations
impl<'opt> RefUnwindSafe for Extractor<'opt>
impl<'opt> Send for Extractor<'opt>
impl<'opt> Sync for Extractor<'opt>
impl<'opt> Unpin for Extractor<'opt>
impl<'opt> UnwindSafe for Extractor<'opt>
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