@@ -31,6 +31,9 @@ pub use self::try_for_each::TryForEach;
3131mod try_filter_map;
3232pub use self :: try_filter_map:: TryFilterMap ;
3333
34+ mod try_concat;
35+ pub use self :: try_concat:: TryConcat ;
36+
3437mod try_fold;
3538pub use self :: try_fold:: TryFold ;
3639
@@ -438,6 +441,47 @@ pub trait TryStreamExt: TryStream {
438441 TryFold :: new ( self , f, init)
439442 }
440443
444+ /// Attempt to concatenate all items of a stream into a single
445+ /// extendable destination, returning a future representing the end result.
446+ ///
447+ /// This combinator will extend the first item with the contents of all
448+ /// the subsequent successful results of the stream. If the stream is empty,
449+ /// the default value will be returned.
450+ ///
451+ /// Works with all collections that implement the [`Extend`](std::iter::Extend) trait.
452+ ///
453+ /// This method is similar to [`concat`](super::StreamExt::concat), but will
454+ /// exit early if an error is encountered in the stream.
455+ ///
456+ /// # Examples
457+ ///
458+ /// ```
459+ /// use futures::channel::mpsc;
460+ /// use futures::executor::block_on;
461+ /// use futures::stream::TryStreamExt;
462+ /// use std::thread;
463+ ///
464+ /// let (mut tx, rx) = mpsc::unbounded::<Result<Vec<i32>, ()>>();
465+ ///
466+ /// thread::spawn(move || {
467+ /// for i in (0..3).rev() {
468+ /// let n = i * 3;
469+ /// tx.unbounded_send(Ok(vec![n + 1, n + 2, n + 3])).unwrap();
470+ /// }
471+ /// });
472+ ///
473+ /// let result = block_on(rx.try_concat());
474+ ///
475+ /// assert_eq!(result, Ok(vec![7, 8, 9, 4, 5, 6, 1, 2, 3]));
476+ /// ```
477+ fn try_concat ( self ) -> TryConcat < Self >
478+ where Self : Sized ,
479+ Self :: Ok : Extend < <<Self as TryStream >:: Ok as IntoIterator >:: Item > +
480+ IntoIterator + Default ,
481+ {
482+ TryConcat :: new ( self )
483+ }
484+
441485 /// Attempt to execute several futures from a stream concurrently.
442486 ///
443487 /// This stream's `Ok` type must be a [`TryFuture`] with an `Error` type
0 commit comments