pub fn json<T: Serialize + ?Sized>(value: &T) -> Result<Box<RawValue>, Error>Expand description
Encodes value as a payload, for the data, info and other payload
fields of requests and proxy results:
#[derive(serde::Serialize)]
struct Message { text: String }
let request = cent::PublishRequest::new("news")
.data(cent::json(&Message { text: "hello".into() })?);
let request = cent::PublishRequest::new("news")
.data(cent::json(&serde_json::json!({"text": "hello"}))?);A serde_json::Value - or any type serde can encode - goes in as it
encodes; a payload already JSON text is RawValue::from_string.
§Errors
Error::Payload when value cannot be encoded: a map whose keys are not
strings, or a Serialize impl’s own error.