Struct alloy_json_rpc::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>
impl Response<&RawValue, &RawValue>
sourcepub fn into_owned(self) -> Response
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>
impl<Payload, ErrData> Response<Payload, ErrData>
sourcepub const fn parse_error(id: Id) -> Self
pub const fn parse_error(id: Id) -> Self
Create a new response with a parsed error payload.
sourcepub const fn invalid_request(id: Id) -> Self
pub const fn invalid_request(id: Id) -> Self
Create a new response with an invalid request error payload.
sourcepub const fn method_not_found(id: Id) -> Self
pub const fn method_not_found(id: Id) -> Self
Create a new response with a method not found error payload.
sourcepub const fn invalid_params(id: Id) -> Self
pub const fn invalid_params(id: Id) -> Self
Create a new response with an invalid params error payload.
sourcepub const fn internal_error(id: Id) -> Self
pub const fn internal_error(id: Id) -> Self
Create a new response with an internal error payload.
sourcepub const fn internal_error_message(id: Id, message: Cow<'static, str>) -> Self
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.
sourcepub const fn internal_error_with_obj(id: Id, data: ErrData) -> Selfwhere
ErrData: RpcObject,
pub const fn internal_error_with_obj(id: Id, data: ErrData) -> Selfwhere
ErrData: RpcObject,
Create a new error response for an internal error with additional data.
sourcepub const fn internal_error_with_message_and_obj(
id: Id,
message: Cow<'static, str>,
data: ErrData,
) -> Selfwhere
ErrData: RpcObject,
pub const fn internal_error_with_message_and_obj(
id: Id,
message: Cow<'static, str>,
data: ErrData,
) -> Selfwhere
ErrData: RpcObject,
Create a new error response for an internal error with a custom message and additional data.
sourcepub const fn is_success(&self) -> bool
pub const fn is_success(&self) -> bool
Returns true
if the response is a success.
source§impl<Payload, ErrData> Response<Payload, ErrData>
impl<Payload, ErrData> Response<Payload, ErrData>
sourcepub fn serialize_payload(&self) -> Result<Response>
pub fn serialize_payload(&self) -> Result<Response>
Serialize the payload of this response.
source§impl<'a, Payload, ErrData> Response<Payload, ErrData>
impl<'a, Payload, ErrData> Response<Payload, ErrData>
sourcepub fn try_success_as<T: Deserialize<'a>>(&'a self) -> Option<Result<T>>
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.
sourcepub fn deser_success<T: DeserializeOwned>(
self,
) -> Result<Response<T, ErrData>, Self>
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>
impl<'a, Payload, ErrData> Response<Payload, ErrData>
sourcepub fn try_error_as<T: Deserialize<'a>>(&'a self) -> Option<Result<T>>
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.
sourcepub fn deser_err<T: DeserializeOwned>(
self,
) -> Result<Response<Payload, T>, Self>
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 asT
, or if the payload is a success.Err(self)
if the payload is an error and can’t be deserialized.
Trait Implementations§
source§impl<'de, Payload, ErrData> Deserialize<'de> for Response<Payload, ErrData>where
Payload: Deserialize<'de>,
ErrData: Deserialize<'de>,
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>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl From<Response> for PubSubItem
impl From<Response> for PubSubItem
source§impl<Payload, ErrData> FromIterator<Response<Payload, ErrData>> for ResponsePacket<Payload, ErrData>
impl<Payload, ErrData> FromIterator<Response<Payload, ErrData>> for ResponsePacket<Payload, ErrData>
Auto Trait Implementations§
impl<Payload, ErrData> Freeze for Response<Payload, ErrData>
impl<Payload, ErrData> RefUnwindSafe for Response<Payload, ErrData>where
Payload: RefUnwindSafe,
ErrData: RefUnwindSafe,
impl<Payload, ErrData> Send for Response<Payload, ErrData>
impl<Payload, ErrData> Sync for Response<Payload, ErrData>
impl<Payload, ErrData> Unpin for Response<Payload, ErrData>
impl<Payload, ErrData> UnwindSafe for Response<Payload, ErrData>where
Payload: UnwindSafe,
ErrData: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.