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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)