Skip to main content

Module ser

Module ser 

Source
Expand description

Single-pass YAML serializer with optional anchors for Rc/Arc/Weak, order preservation (uses the iterator order of your types), simple style controls (block strings & flow containers), and special float handling for NaN/±Inf. No intermediate YAML DOM is built.

Usage example:

use serde::Serialize;
use std::rc::Rc;
use serde_saphyr::{to_string, RcAnchor, LitStr, FlowSeq};

#[derive(Serialize)]
struct Cfg {
    name: String,
    ports: FlowSeq<Vec<u16>>,   // render `[8080, 8081]`
    note: LitStr<'static>,      // render as `|` block
    data: RcAnchor<Vec<i32>>,   // first sight => &a1
    alias: RcAnchor<Vec<i32>>,  // later sight => *a1
}

fn main() {
    let shared = Rc::new(vec![1,2,3]);
    let cfg = Cfg {
        name: "demo".into(),
        ports: FlowSeq(vec![8080, 8081]),
        note: LitStr("line 1\nline 2"),
        data: RcAnchor(shared.clone()),
        alias: RcAnchor(shared),
    };
    println!("{}", to_string(&cfg).unwrap());
}

Re-exports§

pub use self::error::Error;

Modules§

error
options
Serializer options for YAML emission.

Structs§

FoldStr
Force a YAML folded block string using the > style.
FoldString
Owned-string variant of FoldStr that forces a YAML folded block string using the > style.
LitStr
Force a YAML block literal string using the | style.
LitString
Owned-string variant of LitStr that forces a YAML block literal string using the | style.
YamlSerializer
Core YAML serializer used by to_string, to_fmt_writer, and to_io_writer (and their _with_options variants).

Type Aliases§

Result
Result alias.