pub struct JsonRpcResponse {
pub jsonrpc: String,
pub result: Option<Value>,
pub error: Option<JsonRpcError>,
pub id: Option<JsonRpcId>,
}Expand description
JSON-RPC 2.0 Response Object
When a RPC call is made, the Server replies with a Response object.
Fields§
§jsonrpc: StringJSON-RPC version - MUST be exactly “2.0”
result: Option<Value>Result of the method call (present on success)
error: Option<JsonRpcError>Error object (present on failure)
id: Option<JsonRpcId>Request ID (must match the request)
Implementations§
Source§impl JsonRpcResponse
impl JsonRpcResponse
Sourcepub fn success(id: impl Into<JsonRpcId>, result: impl Into<Value>) -> Self
pub fn success(id: impl Into<JsonRpcId>, result: impl Into<Value>) -> Self
Create a successful response
Sourcepub fn error(id: impl Into<JsonRpcId>, error: JsonRpcError) -> Self
pub fn error(id: impl Into<JsonRpcId>, error: JsonRpcError) -> Self
Create an error response
Sourcepub fn notification_ack() -> Self
pub fn notification_ack() -> Self
Create a response for a notification (always None)
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if this is a successful response
Sourcepub fn get_result<T: for<'de> Deserialize<'de>>(
&self,
) -> Result<Option<T>, Error>
pub fn get_result<T: for<'de> Deserialize<'de>>( &self, ) -> Result<Option<T>, Error>
Get the result if successful
Trait Implementations§
Source§impl Clone for JsonRpcResponse
impl Clone for JsonRpcResponse
Source§fn clone(&self) -> JsonRpcResponse
fn clone(&self) -> JsonRpcResponse
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JsonRpcResponse
impl Debug for JsonRpcResponse
Source§impl<'de> Deserialize<'de> for JsonRpcResponse
impl<'de> Deserialize<'de> for JsonRpcResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for JsonRpcResponse
impl RefUnwindSafe for JsonRpcResponse
impl Send for JsonRpcResponse
impl Sync for JsonRpcResponse
impl Unpin for JsonRpcResponse
impl UnsafeUnpin for JsonRpcResponse
impl UnwindSafe for JsonRpcResponse
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