alloy_json_rpc

Struct Response

Source
pub struct Response<Payload = Box<RawValue>, ErrData = Box<RawValue>> {
    pub id: Id,
    pub payload: ResponsePayload<Payload, ErrData>,
}
Expand description

A JSON-RPC 2.0 response object containing a ResponsePayload.

This object is used to represent a JSON-RPC 2.0 response. It may contain either a successful result or an error. The id field is used to match the response to the request that it is responding to, and should be mirrored from the response.

Fields§

§id: Id

The ID of the request that this response is responding to.

§payload: ResponsePayload<Payload, ErrData>

The response payload.

Implementations§

Source§

impl Response<&RawValue, &RawValue>

Source

pub fn into_owned(self) -> Response

Convert this borrowed response to an owned response by copying the data from the deserializer (if necessary).

Source§

impl<Payload, ErrData> Response<Payload, ErrData>

Source

pub const fn parse_error(id: Id) -> Self

Create a new response with a parsed error payload.

Source

pub const fn invalid_request(id: Id) -> Self

Create a new response with an invalid request error payload.

Source

pub const fn method_not_found(id: Id) -> Self

Create a new response with a method not found error payload.

Source

pub const fn invalid_params(id: Id) -> Self

Create a new response with an invalid params error payload.

Source

pub const fn internal_error(id: Id) -> Self

Create a new response with an internal error payload.

Source

pub const fn internal_error_message(id: Id, message: Cow<'static, str>) -> Self

Create a new error response for an internal error with a custom message.

Source

pub const fn internal_error_with_obj(id: Id, data: ErrData) -> Self
where ErrData: RpcObject,

Create a new error response for an internal error with additional data.

Source

pub const fn internal_error_with_message_and_obj( id: Id, message: Cow<'static, str>, data: ErrData, ) -> Self
where ErrData: RpcObject,

Create a new error response for an internal error with a custom message and additional data.

Source

pub const fn is_success(&self) -> bool

Returns true if the response is a success.

Source

pub const fn is_error(&self) -> bool

Returns true if the response is an error.

Source§

impl<Payload, ErrData> Response<Payload, ErrData>
where Payload: RpcObject, ErrData: RpcObject,

Source

pub fn serialize_payload(&self) -> Result<Response>

Serialize the payload of this response.

Source§

impl<'a, Payload, ErrData> Response<Payload, ErrData>
where Payload: AsRef<RawValue> + 'a,

Source

pub fn try_success_as<T: Deserialize<'a>>(&'a self) -> Option<Result<T>>

Attempt to deserialize the success payload, borrowing from the payload if necessary.

See ResponsePayload::try_success_as.

Source

pub fn deser_success<T: DeserializeOwned>( self, ) -> Result<Response<T, ErrData>, Self>

Attempt to deserialize the Success payload, transforming this type.

§Returns
  • Ok(Response<T, ErrData>) if the payload is a success and can be deserialized as T, or if the payload is an error.
  • Err(self) if the payload is a success and can’t be deserialized.
Source§

impl<'a, Payload, ErrData> Response<Payload, ErrData>
where ErrData: Borrow<RawValue> + 'a,

Source

pub fn try_error_as<T: Deserialize<'a>>(&'a self) -> Option<Result<T>>

Attempt to deserialize the error payload, borrowing from the payload if necessary.

See ResponsePayload::try_error_as.

Source

pub fn deser_err<T: DeserializeOwned>( self, ) -> Result<Response<Payload, T>, Self>

Attempt to deserialize the Error payload, transforming this type.

§Returns
  • Ok(Response<Payload, T>) if the payload is an error and can be deserialized as T, or if the payload is a success.
  • Err(self) if the payload is an error and can’t be deserialized.

Trait Implementations§

Source§

impl<Payload: Clone, ErrData: Clone> Clone for Response<Payload, ErrData>

Source§

fn clone(&self) -> Response<Payload, ErrData>

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<Payload: Debug, ErrData: Debug> Debug for Response<Payload, ErrData>

Source§

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

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

impl<'de, Payload, ErrData> Deserialize<'de> for Response<Payload, ErrData>
where Payload: Deserialize<'de>, ErrData: Deserialize<'de>,

Source§

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

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

impl From<Response> for PubSubItem

Source§

fn from(response: Response) -> Self

Converts to this type from the input type.
Source§

impl<Payload, ErrData> FromIterator<Response<Payload, ErrData>> for ResponsePacket<Payload, ErrData>

Source§

fn from_iter<T: IntoIterator<Item = Response<Payload, ErrData>>>( iter: T, ) -> Self

Creates a value from an iterator. Read more
Source§

impl<Payload, ErrData> Serialize for Response<Payload, ErrData>
where Payload: Serialize, ErrData: Serialize,

Source§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<Payload, ErrData> Freeze for Response<Payload, ErrData>
where Payload: Freeze, ErrData: Freeze,

§

impl<Payload, ErrData> RefUnwindSafe for Response<Payload, ErrData>
where Payload: RefUnwindSafe, ErrData: RefUnwindSafe,

§

impl<Payload, ErrData> Send for Response<Payload, ErrData>
where Payload: Send, ErrData: Send,

§

impl<Payload, ErrData> Sync for Response<Payload, ErrData>
where Payload: Sync, ErrData: Sync,

§

impl<Payload, ErrData> Unpin for Response<Payload, ErrData>
where Payload: Unpin, ErrData: Unpin,

§

impl<Payload, ErrData> UnwindSafe for Response<Payload, ErrData>
where Payload: UnwindSafe, ErrData: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> RpcObject for T
where T: RpcParam + RpcReturn,

Source§

impl<T> RpcParam for T
where T: Serialize + Clone + Debug + Send + Sync + Unpin,

Source§

impl<T> RpcReturn for T
where T: DeserializeOwned + Debug + Send + Sync + Unpin + 'static,