alloy_json_rpc

Enum ResponsePayload

Source
pub enum ResponsePayload<Payload = Box<RawValue>, ErrData = Box<RawValue>> {
    Success(Payload),
    Failure(ErrorPayload<ErrData>),
}
Expand description

A JSON-RPC 2.0 response payload.

This enum covers both the success and error cases of a JSON-RPC 2.0 response. It is used to represent the result and error fields of a response object.

§Note

This type does not implement Serialize or Deserialize directly. It is deserialized as part of the Response type.

Variants§

§

Success(Payload)

A successful response payload.

§

Failure(ErrorPayload<ErrData>)

An error response payload.

Implementations§

Source§

impl ResponsePayload<&RawValue, &RawValue>

Source

pub fn into_owned(self) -> ResponsePayload

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

Source§

impl<Payload, ErrData> ResponsePayload<Payload, ErrData>

Source

pub const fn parse_error() -> Self

Create a new error payload for a parse error.

Source

pub const fn invalid_request() -> Self

Create a new error payload for an invalid request.

Source

pub const fn method_not_found() -> Self

Create a new error payload for a method not found error.

Source

pub const fn invalid_params() -> Self

Create a new error payload for an invalid params error.

Source

pub const fn internal_error() -> Self

Create a new error payload for an internal error.

Source

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

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

Source

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

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

Source

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

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

Source

pub const fn as_success(&self) -> Option<&Payload>

Fallible conversion to the successful payload.

Source

pub const fn as_error(&self) -> Option<&ErrorPayload<ErrData>>

Fallible conversion to the error object.

Source

pub const fn is_success(&self) -> bool

Returns true if the response payload is a success.

Source

pub const fn is_error(&self) -> bool

Returns true if the response payload is an error.

Source§

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

Source

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

Convert the inner types into a RawValue by serializing them.

Source§

impl<'a, Payload, ErrData> ResponsePayload<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.

§Returns
  • None if the payload is an error
  • Some(Ok(T)) if the payload is a success and can be deserialized
  • Some(Err(serde_json::Error)) if the payload is a success and can’t be deserialized as T
Source

pub fn deserialize_success<T: DeserializeOwned>( self, ) -> Result<ResponsePayload<T, ErrData>, Self>

Deserialize a Success payload, if possible, transforming this type.

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

impl<'a, Payload, Data> ResponsePayload<Payload, Data>
where Data: 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.

§Returns
  • None if the payload is a success
  • Some(Ok(T)) if the payload is an error and can be deserialized
  • Some(Err(serde_json::Error)) if the payload is an error and can’t be deserialized as T
Source

pub fn deserialize_error<T: DeserializeOwned>( self, ) -> Result<ResponsePayload<Payload, T>, Self>

Deserialize an Error payload, if possible, transforming this type.

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

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> ResponsePayload<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 ResponsePayload<Payload, ErrData>

Source§

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

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

impl<Payload: PartialEq, ErrData: PartialEq> PartialEq for ResponsePayload<Payload, ErrData>

Source§

fn eq(&self, other: &ResponsePayload<Payload, ErrData>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Payload: Eq, ErrData: Eq> Eq for ResponsePayload<Payload, ErrData>

Source§

impl<Payload, ErrData> StructuralPartialEq for ResponsePayload<Payload, ErrData>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<Payload, ErrData> UnwindSafe for ResponsePayload<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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