pub struct Response {
pub jsonrpc: String,
pub result: Option<Value>,
pub error: Option<RpcError>,
pub id: Value,
}Expand description
A single JSON-RPC response object.
[1] https://www.jsonrpc.org/specification#response_object
Fields§
§jsonrpc: StringThe version of the protocol. Must be "2.0". See [JSONRPC_VERSION].
result: Option<Value>The result of the function call that is returned to the client. This is None, if there was an error. This
might also be None, if the call at the server returned null.
error: Option<RpcError>The error triggered by a request, if present.
id: ValueThe ID to identify the to which request this response belongs. If the client sent an ID in the request, this
will be replied here. This is null, if the response is an error that was triggered when trying to parse the
request ID
Implementations§
Source§impl Response
impl Response
Sourcepub fn new_success(id: Value, result: Value) -> Self
pub fn new_success(id: Value, result: Value) -> Self
Creates a new successful response.
Sourcepub fn from_result<R>(
id: Value,
result: Result<R, RpcError>,
) -> Result<Self, Error>where
R: Serialize,
pub fn from_result<R>(
id: Value,
result: Result<R, RpcError>,
) -> Result<Self, Error>where
R: Serialize,
Creates a response object from a [std::result::Result].
Sourcepub fn into_result<R>(self) -> Result<R, Error>where
R: for<'de> Deserialize<'de>,
pub fn into_result<R>(self) -> Result<R, Error>where
R: for<'de> Deserialize<'de>,
Converts the response object to a [std::result::Result]
pub fn from_slice(d: &[u8]) -> Result<Self, Error>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Response
impl<'de> Deserialize<'de> for Response
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 Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin 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