#front-matter #serialization #deserialize #serde #jekyll

serde-frontmatter

Serde支持Jekyll风格的front matter

1个不稳定版本

0.1.0 2021年7月17日

#4 in #jekyll


用于 siena

GPL-3.0 许可证

16KB
53 代码行

serde-frontmatter

Crates.io Docs.rs Build Clippy Audit

这个crate是一个Rust库,用于使用Serde序列化框架与Jekyll风格的front matter。

示例

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");
}

依赖项

~1.8–2.6MB
~54K SLoC