pub struct IpcResponse {
pub jsonrpc: &'static str,
pub id: Value,
pub result: Option<Value>,
pub error: Option<IpcError>,
}Expand description
A JSON-RPC 2.0 response sent back to the client.
Fields§
§jsonrpc: &'static strAlways "2.0".
id: ValueThe request identifier from the corresponding IpcRequest.
result: Option<Value>The successful result payload, if any.
error: Option<IpcError>The error payload, present only when the request failed.
Implementations§
Source§impl IpcResponse
impl IpcResponse
Sourcepub const fn success(id: Value, result: Value) -> Self
pub const fn success(id: Value, result: Value) -> Self
Construct a successful response with the given result payload.
§Examples
let resp = IpcResponse::success(json!(1), json!({"hits": 42}));
assert!(resp.error.is_none());
assert_eq!(resp.result, Some(json!({"hits": 42})));Sourcepub fn error(id: Value, code: i32, message: impl Into<String>) -> Self
pub fn error(id: Value, code: i32, message: impl Into<String>) -> Self
Construct an error response.
§Examples
let resp = IpcResponse::error(json!(1), ERROR_METHOD_NOT_FOUND, "unknown method");
assert!(resp.result.is_none());
assert_eq!(resp.error.as_ref().map(|e| e.code), Some(ERROR_METHOD_NOT_FOUND));Trait Implementations§
Source§impl Debug for IpcResponse
impl Debug for IpcResponse
Auto Trait Implementations§
impl Freeze for IpcResponse
impl RefUnwindSafe for IpcResponse
impl Send for IpcResponse
impl Sync for IpcResponse
impl Unpin for IpcResponse
impl UnsafeUnpin for IpcResponse
impl UnwindSafe for IpcResponse
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