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(
&self,
ids: &HashSet<Id>,
) -> Vec<&Response<Payload, ErrData>>
pub fn responses_by_ids( &self, ids: &HashSet<Id>, ) -> 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 more