@@ -123,6 +123,20 @@ where
123123 self . decoder . decode ( ) . await
124124 }
125125
126+ /// Tries to decode all records into a `Vec`. This eagerly decodes the data.
127+ ///
128+ /// # Errors
129+ /// This function returns an error if the underlying reader returns an error. If
130+ /// the next record is of a different type than `T`, this function returns a
131+ /// [`Error::Conversion`](crate::Error::Conversion) error.
132+ ///
133+ /// # Cancel safety
134+ /// This method is not cancellation safe. If used within a `tokio::select!` statement
135+ /// partially decoded records will be lost and the stream may be corrupted.
136+ pub async fn decode_records < T : HasRType + Clone > ( & mut self ) -> Result < Vec < T > > {
137+ self . decoder . decode_records ( ) . await
138+ }
139+
126140 /// Tries to decode a single record and returns a reference to the record that
127141 /// lasts until the next method call. Returns `Ok(None)` if `reader` has been
128142 /// exhausted.
@@ -335,6 +349,24 @@ where
335349 }
336350 }
337351
352+ /// Tries to decode all records into a `Vec`. This eagerly decodes the data.
353+ ///
354+ /// # Errors
355+ /// This function returns an error if the underlying reader returns an error. If
356+ /// the next record is of a different type than `T`, this function returns a
357+ /// [`Error::Conversion`](crate::Error::Conversion) error.
358+ ///
359+ /// # Cancel safety
360+ /// This method is not cancellation safe. If used within a `tokio::select!` statement
361+ /// partially decoded records will be lost and the stream may be corrupted.
362+ pub async fn decode_records < T : HasRType + Clone > ( & mut self ) -> Result < Vec < T > > {
363+ let mut res = Vec :: new ( ) ;
364+ while let Some ( rec) = self . decode :: < T > ( ) . await ? {
365+ res. push ( rec. clone ( ) ) ;
366+ }
367+ Ok ( res)
368+ }
369+
338370 /// Tries to decode a single record and returns a reference to the record that
339371 /// lasts until the next method call. Returns `None` if `reader` has been
340372 /// exhausted.
0 commit comments