Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5d5064b

Browse files
yoshuawuytsStjepan Glavina
authored and
Stjepan Glavina
committed
add FromStream Result example (#643)
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
1 parent 0ed0d63 commit 5d5064b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎src/result/from_stream.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ where
1010
/// Takes each element in the stream: if it is an `Err`, no further
1111
/// elements are taken, and the `Err` is returned. Should no `Err`
1212
/// occur, a container with the values of each `Result` is returned.
13+
///
14+
/// # Examples
15+
///
16+
/// ```
17+
/// # fn main() { async_std::task::block_on(async {
18+
/// #
19+
/// use async_std::prelude::*;
20+
/// use async_std::stream;
21+
///
22+
/// let v = stream::from_iter(vec![1, 2]);
23+
/// let res: Result<Vec<u32>, &'static str> = v.map(|x: u32|
24+
/// x.checked_add(1).ok_or("Overflow!")
25+
/// ).collect().await;
26+
/// assert_eq!(res, Ok(vec![2, 3]));
27+
/// #
28+
/// # }) }
29+
/// ```
1330
#[inline]
1431
fn from_stream<'a, S: IntoStream<Item = Result<T, E>> + 'a>(
1532
stream: S,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /