pub struct Response<R, E, EM = StrBuf<31>> {
    pub jsonrpc: Version,
    pub payload: Result<R, Error<E, EM>>,
    pub id: Option<Id>,
}
Expand description

Response representation.

When omitting id, it shall be serialized as null and means you’re unable to identify id of Request. Note that JSON-RPCv2 specifies that id must be always present, therefore you’re encouraged to treat missing id as error, unless response is error itself, in which case it might be indication that server treats request as invalid (e.g. unable to parse request’s id).

jsonrpc may be omitted during deserialization and defaults to v2.

Type parameters:

  • R - Type of payload for successful response
  • E - Type of optional data for Error.
  • EM - Type of E::M, which is used for message field of error.

Fields§

§jsonrpc: Version

A String specifying the version of the JSON-RPC protocol.

§payload: Result<R, Error<E, EM>>

Content of response, depending on whether it is success or failure.

§id: Option<Id>

An identifier established by the Client.

If not present, it is sent in response to invalid request (e.g. unable to recognize id).

Must be present always, so None is serialized as null

Implementations§

source§

impl<R, E, EM> Response<R, E, EM>

source

pub const fn result(jsonrpc: Version, result: R, id: Option<Id>) -> Self

Creates successful response.

source

pub const fn error( jsonrpc: Version, error: Error<E, EM>, id: Option<Id> ) -> Self

Creates error response.

Trait Implementations§

source§

impl<R: Clone, E: Clone, EM: Clone> Clone for Response<R, E, EM>

source§

fn clone(&self) -> Response<R, E, EM>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<R: Debug, E: Debug, EM: Debug> Debug for Response<R, E, EM>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, R: Deserialize<'de>, E: Deserialize<'de>, EM: Deserialize<'de>> Deserialize<'de> for Response<R, E, EM>

source§

fn deserialize<D: Deserializer<'de>>(der: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl<R: PartialEq, E: PartialEq, EM: PartialEq> PartialEq<Response<R, E, EM>> for Response<R, E, EM>

source§

fn eq(&self, other: &Response<R, E, EM>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<R: Serialize, E: Serialize, EM: Serialize> Serialize for Response<R, E, EM>

source§

fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl<R, E, EM> StructuralPartialEq for Response<R, E, EM>

Auto Trait Implementations§

§

impl<R, E, EM> RefUnwindSafe for Response<R, E, EM>where E: RefUnwindSafe, EM: RefUnwindSafe, R: RefUnwindSafe,

§

impl<R, E, EM> Send for Response<R, E, EM>where E: Send, EM: Send, R: Send,

§

impl<R, E, EM> Sync for Response<R, E, EM>where E: Sync, EM: Sync, R: Sync,

§

impl<R, E, EM> Unpin for Response<R, E, EM>where E: Unpin, EM: Unpin, R: Unpin,

§

impl<R, E, EM> UnwindSafe for Response<R, E, EM>where E: UnwindSafe, EM: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,