Function to_string

Source
pub fn to_string<T>(value: &T) -> Result<String, SerdeJSON5Error>
where T: Serialize,
Expand description

Basic helper to serialize a value implementing Serialize to a String

ยงExamples

use serde::Serialize;
use json_five::to_string;
#[derive(Serialize)]
struct Test {
    int: u32,
    seq: Vec<&'static str>,
}

let test = Test {
    int: 1,
    seq: vec!["a", "b"],
};
let expected = r#"{"int": 1, "seq": ["a", "b"]}"#;
assert_eq!(to_string(&test).unwrap(), expected);