Crates.io | fronma |
lib.rs | fronma |
version | 0.2.0 |
source | src |
created_at | 2021-11-18 06:11:41.818013 |
updated_at | 2023-06-25 07:14:54.315275 |
description | Front Matter parser. |
homepage | https://github.com/r7kamura/fronma |
repository | https://github.com/r7kamura/fronma |
max_upload_size | |
id | 483838 |
size | 12,121 |
Front Matter parser for Rust.
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");
}
This library supports the following Front Matter formats:
default
feature)toml
feature)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");
}