pub enum ResponsePacket<Payload = Box<RawValue>, ErrData = Box<RawValue>> {
Single(Response<Payload, ErrData>),
Batch(Vec<Response<Payload, ErrData>>),
}
Expand description
A ResponsePacket
is a Response
or a batch of responses.
Variants§
Single(Response<Payload, ErrData>)
A single response.
Batch(Vec<Response<Payload, ErrData>>)
A batch of responses.
Implementations§
Source§impl ResponsePacket<&RawValue, &RawValue>
impl ResponsePacket<&RawValue, &RawValue>
Sourcepub fn into_owned(self) -> ResponsePacket
pub fn into_owned(self) -> ResponsePacket
Convert this borrowed response packet into an owned packet by copying the data from the deserializer (if necessary).
Source§impl<Payload, ErrData> ResponsePacket<Payload, ErrData>
impl<Payload, ErrData> ResponsePacket<Payload, ErrData>
Sourcepub const fn as_single(&self) -> Option<&Response<Payload, ErrData>>
pub const fn as_single(&self) -> Option<&Response<Payload, ErrData>>
Returns the Response
if this packet is ResponsePacket::Single
.
Sourcepub fn as_batch(&self) -> Option<&[Response<Payload, ErrData>]>
pub fn as_batch(&self) -> Option<&[Response<Payload, ErrData>]>
Returns the batch of Response
if this packet is ResponsePacket::Batch
.
Sourcepub fn single_payload(&self) -> Option<&ResponsePayload<Payload, ErrData>>
pub fn single_payload(&self) -> Option<&ResponsePayload<Payload, ErrData>>
Returns the ResponsePayload
if this packet is ResponsePacket::Single
.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true
if the response payload is a success.
For batch responses, this returns true
if all responses are successful.
Sourcepub fn is_error(&self) -> bool
pub fn is_error(&self) -> bool
Returns true
if the response payload is an error.
For batch responses, this returns true
there’s at least one error response.
Sourcepub fn as_error(&self) -> Option<&ErrorPayload<ErrData>>
pub fn as_error(&self) -> Option<&ErrorPayload<ErrData>>
Returns the ErrorPayload if the response is an error.
For batch responses, this returns the first error response.
Sourcepub fn iter_errors(&self) -> impl Iterator<Item = &ErrorPayload<ErrData>> + '_
pub fn iter_errors(&self) -> impl Iterator<Item = &ErrorPayload<ErrData>> + '_
Returns an iterator over the ErrorPayloads in the response.
Sourcepub fn first_error_code(&self) -> Option<i64>
pub fn first_error_code(&self) -> Option<i64>
Returns the first error code in this packet if it contains any error responses.
Sourcepub fn first_error_message(&self) -> Option<&str>
pub fn first_error_message(&self) -> Option<&str>
Returns the first error message in this packet if it contains any error responses.
Sourcepub fn first_error_data(&self) -> Option<&ErrData>
pub fn first_error_data(&self) -> Option<&ErrData>
Returns the first error data in this packet if it contains any error responses.
Sourcepub fn payloads(
&self,
) -> impl Iterator<Item = &ResponsePayload<Payload, ErrData>> + '_
pub fn payloads( &self, ) -> impl Iterator<Item = &ResponsePayload<Payload, ErrData>> + '_
Returns an iterator over the responses’ payloads.
Sourcepub fn first_payload(&self) -> Option<&ResponsePayload<Payload, ErrData>>
pub fn first_payload(&self) -> Option<&ResponsePayload<Payload, ErrData>>
Returns the first ResponsePayload
in this packet.
Sourcepub fn response_ids(&self) -> impl Iterator<Item = &Id> + '_
pub fn response_ids(&self) -> impl Iterator<Item = &Id> + '_
Returns an iterator over the responses’ identifiers.
Sourcepub fn responses_by_ids<K>(
&self,
ids: &HashSet<K>,
) -> Vec<&Response<Payload, ErrData>>
pub fn responses_by_ids<K>( &self, ids: &HashSet<K>, ) -> Vec<&Response<Payload, ErrData>>
Find responses by a list of IDs.
This is intended to be used in conjunction with
RequestPacket::subscription_request_ids
to identify subscription
responses.
§Note
- Responses are not guaranteed to be in the same order.
- Responses are not guaranteed to be in the set.
- If the packet contains duplicate IDs, both will be found.
Trait Implementations§
Source§impl<Payload: Clone, ErrData: Clone> Clone for ResponsePacket<Payload, ErrData>
impl<Payload: Clone, ErrData: Clone> Clone for ResponsePacket<Payload, ErrData>
Source§fn clone(&self) -> ResponsePacket<Payload, ErrData>
fn clone(&self) -> ResponsePacket<Payload, ErrData>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'de, Payload, ErrData> Deserialize<'de> for ResponsePacket<Payload, ErrData>where
Payload: Deserialize<'de>,
ErrData: Deserialize<'de>,
impl<'de, Payload, ErrData> Deserialize<'de> for ResponsePacket<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<Payload, ErrData> From<Vec<Response<Payload, ErrData>>> for ResponsePacket<Payload, ErrData>
impl<Payload, ErrData> From<Vec<Response<Payload, ErrData>>> for ResponsePacket<Payload, ErrData>
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 ResponsePacket<Payload, ErrData>
impl<Payload, ErrData> RefUnwindSafe for ResponsePacket<Payload, ErrData>where
Payload: RefUnwindSafe,
ErrData: RefUnwindSafe,
impl<Payload, ErrData> Send for ResponsePacket<Payload, ErrData>
impl<Payload, ErrData> Sync for ResponsePacket<Payload, ErrData>
impl<Payload, ErrData> Unpin for ResponsePacket<Payload, ErrData>
impl<Payload, ErrData> UnwindSafe for ResponsePacket<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§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> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<'de, T> RpcBorrow<'de> for T
impl<T> RpcRecv for T
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.