Trait SYMLSerialize

Source
pub trait SYMLSerialize {
    // Required method
    fn serialize_min<F: FnMut(Arguments<'_>)>(&self, f: &mut F);

    // Provided methods
    fn serialize<F: FnMut(Arguments<'_>)>(&self, f: &mut F, indent: usize) { ... }
    fn serialize_to_string(&self, indent: usize) -> String { ... }
    fn serialize_min_to_string(&self) -> String { ... }
}

Required Methods§

Source

fn serialize_min<F: FnMut(Arguments<'_>)>(&self, f: &mut F)

Serialize to a shorter form

§Examples
let value = Value::from([
    "2".into(),
    Value::from(["3", "4", "5"]),
    [("x", "6")].into()
]);
let mut buf = String::new();
value.serialize_min(&mut |args| write!(buf, "{args}").unwrap());
assert_eq!(&buf, "[2,[3,4,5],{x:6}]");

Provided Methods§

Source

fn serialize<F: FnMut(Arguments<'_>)>(&self, f: &mut F, indent: usize)

Serialize to standard form

§Examples
let value = Value::from([
    "2".into(),
    Value::from(["3", "4", "5"]),
    [("x", "6")].into()
]);
let mut buf = String::new();
value.serialize(&mut |args| write!(buf, "{args}").unwrap(), 0);
buf.push('\n');
assert_eq!(&buf, "\
- 2
- - 3
  - 4
  - 5
- x: 6
");
Source

fn serialize_to_string(&self, indent: usize) -> String

Same as serialize, but collect to string

§Examples
let value = Value::from([
    "2".into(),
    Value::from(["3", "4", "5"]),
    [("x", "6")].into()
]);
let mut buf = String::new();
value.serialize(&mut |args| write!(buf, "{args}").unwrap(), 0);
assert_eq!(buf, value.serialize_to_string(0));
Source

fn serialize_min_to_string(&self) -> String

Same as serialize_min, but collect to string

§Examples
let value = Value::from([
    "2".into(),
    Value::from(["3", "4", "5"]),
    [("x", "6")].into()
]);
let mut buf = String::new();
value.serialize_min(&mut |args| write!(buf, "{args}").unwrap());
assert_eq!(buf, value.serialize_min_to_string());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SYMLSerialize for String

Source§

impl SYMLSerialize for LinkedHashMap<String, Value>

Source§

fn serialize_min<F: FnMut(Arguments<'_>)>(&self, f: &mut F)

Source§

fn serialize<F: FnMut(Arguments<'_>)>(&self, f: &mut F, indent: usize)

Source§

impl SYMLSerialize for [Value]

Source§

fn serialize_min<F: FnMut(Arguments<'_>)>(&self, f: &mut F)

Source§

fn serialize<F: FnMut(Arguments<'_>)>(&self, f: &mut F, indent: usize)

Implementors§