Function json_with_comments::ser::to_write
source · pub fn to_write<W, F, S>(value: S, write: W, formatter: F) -> Result<()>
Expand description
Serialize struct S
as a JSON with comments text of the given writer.
§Examples
use serde::Serialize;
#[derive(Serialize)]
struct Product {
name: String,
price: u32,
}
let mut write = Vec::new();
let product = Product { name: "candy".to_string(), price: 100 };
json_with_comments::to_write(product, &mut write, json_with_comments::ser::formatter::minify::MinifyFormatter).unwrap();
assert_eq!(String::from_utf8(write).unwrap(), r#"{"name":"candy","price":100}"#);