pub fn to_value<T>(value: T) -> Result<Value, SerializeError>where
T: Serialize,Available on crate feature
serde only.Expand description
Serializes the given value into a JSON Value.
§Example
use serde::Serialize;
use jstrict::{json, Value};
#[derive(Serialize)]
struct User {
fingerprint: String,
location: String,
}
let u = User {
fingerprint: "0xF9BA143B95FF6D82".to_owned(),
location: "Menlo Park, CA".to_owned(),
};
let expected: Value = json!({
"fingerprint": "0xF9BA143B95FF6D82",
"location": "Menlo Park, CA",
});
let v = jstrict::to_value(u).unwrap();
assert_eq!(v, expected);§Errors
Returns SerializeError if value cannot be serialized to JSON.