pub struct Json(pub String);Expand description
A JSON document as the host passes it: a value, a live message, an event payload, a call’s request or response.
Tuple Fields§
§0: StringImplementations§
Source§impl Json
impl Json
Sourcepub fn from_value<T: Serialize + ?Sized>(value: &T) -> Result<Self>
pub fn from_value<T: Serialize + ?Sized>(value: &T) -> Result<Self>
Serializes value.
Examples found in repository?
examples/together_companion.rs (line 84)
73 fn call(&self, method: &str, _request: Json, cx: &Context) -> Result<Json, Error> {
74 match method {
75 "rebuild" => {
76 let started = !self.running.replace(true);
77 if started {
78 cx.spawn(rebuild(
79 cx.clone(),
80 self.builds.clone(),
81 self.running.clone(),
82 ));
83 }
84 Json::from_value(&started)
85 }
86 other => Err(Error::Invalid(format!("unknown method {other}"))),
87 }
88 }Sourcepub fn parse<T: DeserializeOwned>(&self) -> Result<T>
pub fn parse<T: DeserializeOwned>(&self) -> Result<T>
Deserializes the document.
pub fn as_str(&self) -> &str
pub fn into_string(self) -> String
Trait Implementations§
impl Eq for Json
impl StructuralPartialEq for Json
Auto Trait Implementations§
impl Freeze for Json
impl RefUnwindSafe for Json
impl Send for Json
impl Sync for Json
impl Unpin for Json
impl UnsafeUnpin for Json
impl UnwindSafe for Json
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more