@@ -10,6 +10,12 @@ use futures_core::stream::TryStream;
1010mod err_into;
1111pub use self :: err_into:: ErrInto ;
1212
13+ mod map_ok;
14+ pub use self :: map_ok:: MapOk ;
15+
16+ mod map_err;
17+ pub use self :: map_err:: MapErr ;
18+
1319mod try_next;
1420pub use self :: try_next:: TryNext ;
1521
@@ -51,6 +57,58 @@ pub trait TryStreamExt: TryStream {
5157 ErrInto :: new ( self )
5258 }
5359
60+ /// Wraps the current stream in a new stream which maps the success value
61+ /// using the provided closure.
62+ ///
63+ /// # Examples
64+ ///
65+ /// ```
66+ /// #![feature(async_await, await_macro)]
67+ /// # futures::executor::block_on(async {
68+ /// use futures::{stream, TryStreamExt};
69+ ///
70+ /// let mut stream =
71+ /// stream::iter(vec![Ok(5), Err(0)])
72+ /// .map_ok(|x| x + 2);
73+ ///
74+ /// assert_eq!(await!(stream.try_next()), Ok(Some(7)));
75+ /// assert_eq!(await!(stream.try_next()), Err(0));
76+ /// # })
77+ /// ```
78+ fn map_ok < T , F > ( self , f : F ) -> MapOk < Self , F >
79+ where
80+ Self : Sized ,
81+ F : FnMut ( Self :: Ok ) -> T ,
82+ {
83+ MapOk :: new ( self , f)
84+ }
85+
86+ /// Wraps the current stream in a new stream which maps the error value
87+ /// using the provided closure.
88+ ///
89+ /// # Examples
90+ ///
91+ /// ```
92+ /// #![feature(async_await, await_macro)]
93+ /// # futures::executor::block_on(async {
94+ /// use futures::{stream, TryStreamExt};
95+ ///
96+ /// let mut stream =
97+ /// stream::iter(vec![Ok(5), Err(0)])
98+ /// .map_err(|x| x + 2);
99+ ///
100+ /// assert_eq!(await!(stream.try_next()), Ok(Some(5)));
101+ /// assert_eq!(await!(stream.try_next()), Err(2));
102+ /// # })
103+ /// ```
104+ fn map_err < E , F > ( self , f : F ) -> MapErr < Self , F >
105+ where
106+ Self : Sized ,
107+ F : FnMut ( Self :: Error ) -> E ,
108+ {
109+ MapErr :: new ( self , f)
110+ }
111+
54112 /// Creates a future that attempts to resolve the next item in the stream.
55113 /// If an error is encountered before the next item, the error is returned
56114 /// instead.
0 commit comments