@@ -241,6 +241,27 @@ impl BorrowedResponsePacket<'_> {
241
241
}
242
242
243
243
impl < Payload , ErrData > ResponsePacket < Payload , ErrData > {
244
+ /// Returns the [`Response`] if this packet is [`ResponsePacket::Single`].
245
+ pub const fn as_single ( & self ) -> Option < & Response < Payload , ErrData > > {
246
+ match self {
247
+ Self :: Single ( resp) => Some ( resp) ,
248
+ Self :: Batch ( _) => None ,
249
+ }
250
+ }
251
+
252
+ /// Returns the batch of [`Response`] if this packet is [`ResponsePacket::Batch`].
253
+ pub fn as_batch ( & self ) -> Option < & [ Response < Payload , ErrData > ] > {
254
+ match self {
255
+ Self :: Batch ( resp) => Some ( resp. as_slice ( ) ) ,
256
+ Self :: Single ( _) => None ,
257
+ }
258
+ }
259
+
260
+ /// Returns the [`ResponsePayload`] if this packet is [`ResponsePacket::Single`].
261
+ pub fn single_payload ( & self ) -> Option < & ResponsePayload < Payload , ErrData > > {
262
+ self . as_single ( ) . map ( |resp| & resp. payload )
263
+ }
264
+
244
265
/// Returns `true` if the response payload is a success.
245
266
///
246
267
/// For batch responses, this returns `true` if __all__ responses are successful.
@@ -289,6 +310,11 @@ impl<Payload, ErrData> ResponsePacket<Payload, ErrData> {
289
310
self . responses ( ) . iter ( ) . map ( |resp| & resp. payload )
290
311
}
291
312
313
+ /// Returns the first [`ResponsePayload`] in this packet.
314
+ pub fn first_payload ( & self ) -> Option < & ResponsePayload < Payload , ErrData > > {
315
+ self . payloads ( ) . next ( )
316
+ }
317
+
292
318
/// Returns an iterator over the responses' identifiers.
293
319
pub fn response_ids ( & self ) -> impl Iterator < Item = & Id > + ' _ {
294
320
self . responses ( ) . iter ( ) . map ( |resp| & resp. id )
0 commit comments