2 unstable releases

0.2.0 Jun 25, 2023
0.1.1 Nov 18, 2021

#2638 in Parser implementations

Download history 9/week @ 2024-07-21 13/week @ 2024-07-28 10/week @ 2024-08-04 12/week @ 2024-08-11 12/week @ 2024-08-18 16/week @ 2024-08-25 7/week @ 2024-09-01 8/week @ 2024-09-08 8/week @ 2024-09-15 25/week @ 2024-09-22 78/week @ 2024-09-29 26/week @ 2024-10-06 73/week @ 2024-10-13 28/week @ 2024-10-20 23/week @ 2024-10-27 18/week @ 2024-11-03

145 downloads per month
Used in 2 crates

MIT license

12KB
256 lines

fronma

test

Front Matter parser for Rust.

Usage

Add this crate as a dependency:

[dependencies]
fronma = "~0.1"

then use fronma::parser::parse to parse text that has YAML Front Matter:

use fronma::parser::parse;
use serde::Deserialize;

#[derive(Deserialize)]
struct Headers {
  title: String,
}

fn main() {
    let text = r#"---
title: A
---
B
"#;

    let data = parse::<Headers>(text).unwrap();
    assert_eq!(data.headers.title, "A");
    assert_eq!(data.body, "B\n");
}

Other formats

This library supports the following Front Matter formats:

  • YAML (supported by default feature)
  • TOML (requires toml feature)
  • JSON (requires json feature)

For example, when you want to use TOML format, add this crate with toml feature:

[dependencies]
fronma = { version = "~0.1", features = ["toml"] }

then use fronma::parser::parse_with_engine like this:

use fronma::engines::Toml;
use fronma::parser::parse_with_engine;
use serde::Deserialize;

#[derive(Deserialize)]
struct Headers {
  title: String,
}

fn main() {
    let text = r#"---
title = "dummy_title"
---
dummy_body
"#;
    let result = parse_with_engine::<Headers, Toml>(text).unwrap();
    assert_eq!(result.headers.title, "dummy_title");
    assert_eq!(result.body, "dummy_body\n");
}

Dependencies

~1.6–2MB
~42K SLoC