pub struct Response {
pub ok: bool,
pub id: Option<Value>,
pub error: Option<ErrorBody>,
pub fields: Map<String, Value>,
}Expand description
JSON result printed by the CLI and returned by dispatch.
Fields§
§ok: boolWhether the action completed.
id: Option<Value>Request id, when the caller sent one.
error: Option<ErrorBody>Present when ok is false.
fields: Map<String, Value>Extra fields flattened into the JSON object.
Implementations§
Source§impl Response
impl Response
Sourcepub fn success(data: Value) -> Self
pub fn success(data: Value) -> Self
Successful response. data must be a JSON object; other values are stored as result.
Sourcepub fn failure(code: impl Into<String>, message: impl Into<String>) -> Self
pub fn failure(code: impl Into<String>, message: impl Into<String>) -> Self
Failed response with a stable code and message.
Sourcepub fn from_error(error: ComputerError) -> Self
pub fn from_error(error: ComputerError) -> Self
Failed response from a ComputerError.
Sourcepub fn to_json_line(&self, pretty: bool) -> String
pub fn to_json_line(&self, pretty: bool) -> String
Serialize as compact or pretty JSON, followed by a newline.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Response
impl<'de> Deserialize<'de> for Response
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<ComputerError> for Response
impl From<ComputerError> for Response
Source§fn from(error: ComputerError) -> Self
fn from(error: ComputerError) -> Self
Converts to this type from the input type.
impl StructuralPartialEq for Response
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
impl UnwindSafe for Response
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