Expand description
Serde format crate for Markdown documents with a structured fields fence and ordered body sections.
A root struct’s non-body fields map to an optional first YAML, JSON, or
TOML block (fenced or bare). Fields listed in Markdown::BODY_FIELDS
map to body sections split on top-level ---. Serialize defaults to a
labeled yaml fence; JSON and TOML only when the caller passes
Format::Json / Format::Toml. Default crate features are yaml,
json, toml, and derive. Feature buffa is off by default. A fence
language not in the compiled features is ErrorKind::FormatDisabled.
Documents are UTF-8: from_slice fails with ErrorKind::Syntax on
invalid bytes.
Feature tokio (off by default) adds the module serde_markdown::tokio: the
async twin of every function here, under the same name. It runs the same
algorithm in steps and yields to the scheduler between them when the
task’s cooperative budget is spent; no thread is spawned.
Google well-known types in the fence or body use that field type’s proto3
JSON serde. This crate does not parse RFC 3339 itself. Callers who pack
protobuf Any must install a type registry (buffa_types::register_wkt_types)
the same way they do for serde_json.
§Example
use serde::{Deserialize, Serialize};
use serde_markdown::{from_str, to_string, Markdown};
#[derive(Debug, PartialEq, Serialize, Deserialize, Markdown)]
struct Page {
title: String,
#[markdown(body)]
body: String,
}
let page = Page {
title: "Hi".into(),
body: "Hello".into(),
};
let md = to_string(&page)?;
let back: Page = from_str(&md)?;
assert_eq!(page, back);Modules§
- buffa
- Buffa codegen attributes for
(markdown.body) = true. - tokio
- The async form of the crate, behind the feature
tokio.
Structs§
- Error
- Failure while reading or writing a Markdown document.
Enums§
- Error
Kind - Classification for
Error. Match this; do not parseDisplay. New kinds may be added, so amatchneeds a_arm. - Fields
Layout - Whether the serialized fields block is a fenced code block or a bare mapping.
- Format
- Fence language used when serializing the fields block.
Constants§
- PROTO_
INCLUDE - Directory containing
markdown/options.protofor include paths.
Traits§
- Markdown
- Marks which Serde field names of a root struct are Markdown body sections.
Functions§
- from_
reader - Deserialize a Markdown document by reading
readerto the end. - from_
slice - Deserialize a Markdown document from UTF-8
bytes. - from_
str - Deserialize a Markdown document from
s. - to_
string - Serialize
valueas a fenced YAML Markdown document. - to_
string_ with - Serialize
valuewith an explicit fence language and fields layout. - to_
string_ with_ format - Serialize
valueas a fenced Markdown document informat. - to_vec
- Serialize
valueas UTF-8 bytes of a fenced YAML Markdown document. - to_
writer - Write
valueas a fenced YAML Markdown document towriter.
Derive Macros§
- Markdown
- Implements
serde_markdown::Markdownfor a named struct.