Crates.io | serde-frontmatter |
lib.rs | serde-frontmatter |
version | 0.1.0 |
source | src |
created_at | 2021-07-17 16:42:41.535873 |
updated_at | 2021-07-17 16:42:41.535873 |
description | Serde support for Jekyll front matter |
homepage | https://github.com/ewpratten/serde-frontmatter |
repository | https://github.com/ewpratten/serde-frontmatter |
max_upload_size | |
id | 424088 |
size | 43,734 |
This crate is a Rust library for using the Serde serialization framework with Jekyll-style 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");
}