pub fn serialize_with_context<T, S, C>(
value: &T,
serializer: S,
context: C,
) -> Result<S::Ok, S::Error>Expand description
Serialize a value with some provided context.
Provided context can then be accessed using context_scope in implementations of
Serialize. This function is meant to be the contextful version of value.serialize(serializer).
§Example
This is only a minimal example for this function’s usage. You can find more in this crate’s
top-level documentation as well as its examples directory.
let mut bytes = Vec::<u8>::new();
let mut serializer = serde_json::Serializer::new(&mut bytes);
serialize_with_context(&vec![1, 2, 3], &mut serializer, ())?;
assert_eq!(bytes, b"[1,2,3]");