pub struct Extractor { /* private fields */ }
Expand description

Holds configuration for how front-matter and data should be extracted from a string.

  1. Instantiate using Extractor::new() with the desired Splitter
  2. (Optional) Call .with_modifier() with a desired Modifier; repeat as necessary
  3. 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(String::from("+++")))
    .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(String::from("-- ")))
    .with_modifier(Modifier::StripPrefix(String::from("-- ")))
    .extract(input);

Front-matter output:

meta:
  field_one: 10
  field_two:
    - 2
    - 4

Data output:

SELECT version();

Implementations

Instantiate a new Extractor config.

Add a modifier to the front-matter returned by .extract().

Split the given input string into a tuple of front-matter and data, applying any modifiers specified with .with_modifier().

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.