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
)