1 unstable release

0.1.0 Jul 17, 2021

#3 in #jekyll

Download history 2/week @ 2024-11-13 2/week @ 2024-11-20 11/week @ 2024-11-27 51/week @ 2024-12-04 21/week @ 2024-12-11 7/week @ 2024-12-18 7/week @ 2025-01-15 2/week @ 2025-01-22 10/week @ 2025-02-05 10/week @ 2025-02-12 20/week @ 2025-02-19 13/week @ 2025-02-26

53 downloads per month
Used in siena

GPL-3.0 license

16KB
53 lines

serde-frontmatter

Crates.io Docs.rs Build Clippy Audit

This crate is a Rust library for using the Serde serialization framework with Jekyll-style front matter.

Examples

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub struct MyData {
    pub title: String
}

fn main() {
    // Serialize
    let front_matter = MyData { title: "Hello, World!".to_string() };
    let content = "This is some content";
    let output = serde_frontmatter::serialize(front_matter, content).unwrap();
    assert_eq!("---\ntitle: \"Hello, World!\"\n\n---\nThis is some content", output);

    // Deserialize
    let input = "---\ntitle: Hello, World!\n---\nThis is some content";
    let (front_matter, content) = serde_frontmatter::deserialize::<MyData>(input).unwrap();
    assert_eq!(front_matter, MyData { title: "Hello, World!".to_string() });
    assert_eq!(content, "\nThis is some content");
}

Dependencies

~1.8–2.4MB
~51K SLoC