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§
Structs§
- FoldStr
- Force a YAML folded block string using the
>style. - Fold
String - Owned-string variant of
FoldStrthat forces a YAML folded block string using the>style. - LitStr
- Force a YAML block literal string using the
|style. - LitString
- Owned-string variant of
LitStrthat forces a YAML block literal string using the|style. - Yaml
Serializer - Core YAML serializer used by
to_string,to_fmt_writer, andto_io_writer(and their_with_optionsvariants).
Type Aliases§
- Result
- Result alias.