mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-26 19:58:50 +01:00
526 lines
143 KiB
HTML
526 lines
143 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `TryStreamExt` trait in crate `futures`."><meta name="keywords" content="rust, rustlang, rust-lang, TryStreamExt"><title>futures::stream::TryStreamExt - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../futures/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait TryStreamExt</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.and_then">and_then</a><a href="#method.err_into">err_into</a><a href="#method.map_err">map_err</a><a href="#method.try_flatten">try_flatten</a><a href="#method.into_stream">into_stream</a><a href="#method.or_else">or_else</a><a href="#method.try_next">try_next</a><a href="#method.try_for_each">try_for_each</a><a href="#method.try_filter">try_filter</a><a href="#method.try_filter_map">try_filter_map</a><a href="#method.try_collect">try_collect</a><a href="#method.try_concat">try_concat</a><a href="#method.try_fold">try_fold</a><a href="#method.try_skip_while">try_skip_while</a><a href="#method.try_take_while">try_take_while</a><a href="#method.try_buffer_unordered">try_buffer_unordered</a><a href="#method.try_buffered">try_buffered</a><a href="#method.try_for_each_concurrent">try_for_each_concurrent</a><a href="#method.into_async_read">into_async_read</a><a href="#method.map_ok">map_ok</a><a href="#method.inspect_ok">inspect_ok</a><a href="#method.inspect_err">inspect_err</a><a href="#method.try_poll_next_unpin">try_poll_next_unpin</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">futures</a>::<wbr><a href="index.html">stream</a></p><div id="sidebar-vars" data-name="TryStreamExt" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Trait <a href="../index.html">futures</a>::<wbr><a href="index.html">stream</a>::<wbr><a class="trait" href="">TryStreamExt</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#144-1002" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait TryStreamExt: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a> {
|
||
pub fn <a href="#method.err_into" class="fnname">err_into</a><E>(self) -> <a class="struct" href="../../futures/stream/struct.ErrInto.html" title="struct futures::stream::ErrInto">ErrInto</a><Self, E><br> <span class="where">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><E></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.map_ok" class="fnname">map_ok</a><T, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.MapOk.html" title="struct futures::stream::MapOk">MapOk</a><Self, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> T</span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.map_err" class="fnname">map_err</a><E, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.MapErr.html" title="struct futures::stream::MapErr">MapErr</a><Self, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>) -> E</span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.and_then" class="fnname">and_then</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.AndThen.html" title="struct futures::stream::AndThen">AndThen</a><Self, Fut, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.or_else" class="fnname">or_else</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.OrElse.html" title="struct futures::stream::OrElse">OrElse</a><Self, Fut, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.inspect_ok" class="fnname">inspect_ok</a><F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.InspectOk.html" title="struct futures::stream::InspectOk">InspectOk</a><Self, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>)</span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.inspect_err" class="fnname">inspect_err</a><F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.InspectErr.html" title="struct futures::stream::InspectErr">InspectErr</a><Self, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>)</span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.into_stream" class="fnname">into_stream</a>(self) -> <a class="struct" href="../../futures/stream/struct.IntoStream.html" title="struct futures::stream::IntoStream">IntoStream</a><Self> { ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_next" class="fnname">try_next</a>(&mut self) -> <a class="struct" href="../../futures/stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, St></h3><code class="content"><span class="where fmt-newline">impl<'_, St> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, St> <span class="where fmt-newline">where<br> St: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_for_each" class="fnname">try_for_each</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><St, Fut, F></h3><code class="content"><span class="where fmt-newline">impl<St, Fut, F> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><St, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error = <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_skip_while" class="fnname">try_skip_while</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TrySkipWhile.html" title="struct futures::stream::TrySkipWhile">TrySkipWhile</a><Self, Fut, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_take_while" class="fnname">try_take_while</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TryTakeWhile.html" title="struct futures::stream::TryTakeWhile">TryTakeWhile</a><Self, Fut, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_for_each_concurrent" class="fnname">try_for_each_concurrent</a><Fut, F>(<br> self, <br> limit: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>>>, <br> f: F<br> ) -> <a class="struct" href="../../futures/stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><St, Fut, F></h3><code class="content"><span class="where fmt-newline">impl<St, Fut, F> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><St, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a><Output = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>>,<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a><Output = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_collect" class="fnname">try_collect</a><C>(self) -> <a class="struct" href="../../futures/stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><Self, C><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><St, C></h3><code class="content"><span class="where fmt-newline">impl<St, C> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><St, C> <span class="where fmt-newline">where<br> C: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>,<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><C, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span><br> <span class="where">where<br> C: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_filter" class="fnname">try_filter</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TryFilter.html" title="struct futures::stream::TryFilter">TryFilter</a><Self, Fut, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a><Output = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_filter_map" class="fnname">try_filter_map</a><Fut, F, T>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TryFilterMap.html" title="struct futures::stream::TryFilterMap">TryFilterMap</a><Self, Fut, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_flatten" class="fnname">try_flatten</a>(self) -> <a class="struct" href="../../futures/stream/struct.TryFlatten.html" title="struct futures::stream::TryFlatten">TryFlatten</a><Self><br> <span class="where">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<br> <Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_fold" class="fnname">try_fold</a><T, Fut, F>(self, init: T, f: F) -> <a class="struct" href="../../futures/stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><Self, Fut, T, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><St, Fut, T, F></h3><code class="content"><span class="where fmt-newline">impl<St, Fut, T, F> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><St, Fut, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = T, Error = <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T, Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = T, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_concat" class="fnname">try_concat</a>(self) -> <a class="struct" href="../../futures/stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><St></h3><code class="content"><span class="where fmt-newline">impl<St> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><St> <span class="where fmt-newline">where<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<br> <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>>,<br> <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,<br> <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span><br> <span class="where">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>>,<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_buffer_unordered" class="fnname">try_buffer_unordered</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../futures/stream/struct.TryBufferUnordered.html" title="struct futures::stream::TryBufferUnordered">TryBufferUnordered</a><Self><br> <span class="where">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>,<br> <Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>>::<a class="type" href="../../futures/future/trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a> == Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_buffered" class="fnname">try_buffered</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../futures/stream/struct.TryBuffered.html" title="struct futures::stream::TryBuffered">TryBuffered</a><Self><br> <span class="where">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>,<br> <Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>>::<a class="type" href="../../futures/future/trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a> == Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.try_poll_next_unpin" class="fnname">try_poll_next_unpin</a>(<br> &mut self, <br> cx: &mut <a class="struct" href="../../futures/task/struct.Context.html" title="struct futures::task::Context">Context</a><'_><br> ) -> <a class="enum" href="../../futures/task/enum.Poll.html" title="enum futures::task::Poll">Poll</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>, Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>>><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> pub fn <a href="#method.into_async_read" class="fnname">into_async_read</a>(self) -> <a class="struct" href="../../futures/stream/struct.IntoAsyncRead.html" title="struct futures::stream::IntoAsyncRead">IntoAsyncRead</a><Self><br> <span class="where">where<br> Self: <a class="trait" href="../../futures/stream/trait.TryStreamExt.html" title="trait futures::stream::TryStreamExt">TryStreamExt</a><Error = <a class="struct" href="../../futures/io/struct.Error.html" title="struct futures::io::Error">Error</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>></span>,
|
||
{ ... }
|
||
}</pre></div><div class="docblock"><p>Adapters specific to <code>Result</code>-returning streams</p>
|
||
</div><h2 id="provided-methods" class="small-section-header">Provided methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><h3 id="method.err_into" class="method"><code>pub fn <a href="#method.err_into" class="fnname">err_into</a><E>(self) -> <a class="struct" href="../../futures/stream/struct.ErrInto.html" title="struct futures::stream::ErrInto">ErrInto</a><Self, E> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><E>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#162-165" title="goto source code">[src]</a></h3><div class="docblock"><p>Wraps the current stream in a new stream which converts the error type
|
||
into the one provided.</p>
|
||
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stream</span> <span class="op">=</span>
|
||
<span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(()), <span class="prelude-val">Err</span>(<span class="number">5i32</span>)])
|
||
.<span class="ident">err_into</span>::<span class="op"><</span><span class="ident">i64</span><span class="op">></span>();
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">try_next</span>().<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(())));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">try_next</span>().<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">5i64</span>));</pre></div>
|
||
</div><h3 id="method.map_ok" class="method"><code>pub fn <a href="#method.map_ok" class="fnname">map_ok</a><T, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.MapOk.html" title="struct futures::stream::MapOk">MapOk</a><Self, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> T, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#187-190" title="goto source code">[src]</a></h3><div class="docblock"><p>Wraps the current stream in a new stream which maps the success value
|
||
using the provided closure.</p>
|
||
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stream</span> <span class="op">=</span>
|
||
<span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(<span class="number">5</span>), <span class="prelude-val">Err</span>(<span class="number">0</span>)])
|
||
.<span class="ident">map_ok</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">+</span> <span class="number">2</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">try_next</span>().<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(<span class="number">7</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">try_next</span>().<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">0</span>));</pre></div>
|
||
</div><h3 id="method.map_err" class="method"><code>pub fn <a href="#method.map_err" class="fnname">map_err</a><E, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.MapErr.html" title="struct futures::stream::MapErr">MapErr</a><Self, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>) -> E, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#212-215" title="goto source code">[src]</a></h3><div class="docblock"><p>Wraps the current stream in a new stream which maps the error value
|
||
using the provided closure.</p>
|
||
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stream</span> <span class="op">=</span>
|
||
<span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(<span class="number">5</span>), <span class="prelude-val">Err</span>(<span class="number">0</span>)])
|
||
.<span class="ident">map_err</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">+</span> <span class="number">2</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">try_next</span>().<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(<span class="number">5</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">try_next</span>().<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">2</span>));</pre></div>
|
||
</div><h3 id="method.and_then" class="method"><code>pub fn <a href="#method.and_then" class="fnname">and_then</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.AndThen.html" title="struct futures::stream::AndThen">AndThen</a><Self, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#258-262" title="goto source code">[src]</a></h3><div class="docblock"><p>Chain on a computation for when a value is ready, passing the successful
|
||
results to the provided closure <code>f</code>.</p>
|
||
<p>This function can be used to run a unit of work when the next successful
|
||
value on a stream is ready. The closure provided will be yielded a value
|
||
when ready, and the returned future will then be run to completion to
|
||
produce the next value on this stream.</p>
|
||
<p>Any errors produced by this stream will not be passed to the closure,
|
||
and will be passed through.</p>
|
||
<p>The returned value of the closure must implement the <code>TryFuture</code> trait
|
||
and can represent some more work to be done before the composed stream
|
||
is finished.</p>
|
||
<p>Note that this function consumes the receiving stream and returns a
|
||
wrapped version of it.</p>
|
||
<p>To process the entire stream and return a single future representing
|
||
success or error, use <code>try_for_each</code> instead.</p>
|
||
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">mpsc</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::<span class="ident">TryStreamExt</span>;
|
||
|
||
<span class="kw">let</span> (<span class="ident">_tx</span>, <span class="ident">rx</span>) <span class="op">=</span> <span class="ident">mpsc</span>::<span class="ident">channel</span>::<span class="op"><</span><span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">i32</span>, ()<span class="op">></span><span class="op">></span>(<span class="number">1</span>);
|
||
|
||
<span class="kw">let</span> <span class="ident">rx</span> <span class="op">=</span> <span class="ident">rx</span>.<span class="ident">and_then</span>(<span class="op">|</span><span class="ident">result</span><span class="op">|</span> {
|
||
<span class="ident">future</span>::<span class="ident">ok</span>(<span class="kw">if</span> <span class="ident">result</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span> {
|
||
<span class="prelude-val">Some</span>(<span class="ident">result</span>)
|
||
} <span class="kw">else</span> {
|
||
<span class="prelude-val">None</span>
|
||
})
|
||
});</pre></div>
|
||
</div><h3 id="method.or_else" class="method"><code>pub fn <a href="#method.or_else" class="fnname">or_else</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.OrElse.html" title="struct futures::stream::OrElse">OrElse</a><Self, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#284-288" title="goto source code">[src]</a></h3><div class="docblock"><p>Chain on a computation for when an error happens, passing the
|
||
erroneous result to the provided closure <code>f</code>.</p>
|
||
<p>This function can be used to run a unit of work and attempt to recover from
|
||
an error if one happens. The closure provided will be yielded an error
|
||
when one appears, and the returned future will then be run to completion
|
||
to produce the next value on this stream.</p>
|
||
<p>Any successful values produced by this stream will not be passed to the
|
||
closure, and will be passed through.</p>
|
||
<p>The returned value of the closure must implement the <a href="../../futures/future/trait.TryFuture.html"><code>TryFuture</code></a> trait
|
||
and can represent some more work to be done before the composed stream
|
||
is finished.</p>
|
||
<p>Note that this function consumes the receiving stream and returns a
|
||
wrapped version of it.</p>
|
||
</div><h3 id="method.inspect_ok" class="method"><code>pub fn <a href="#method.inspect_ok" class="fnname">inspect_ok</a><F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.InspectOk.html" title="struct futures::stream::InspectOk">InspectOk</a><Self, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>), </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#299-302" title="goto source code">[src]</a></h3><div class="docblock"><p>Do something with the success value of this stream, afterwards passing
|
||
it on.</p>
|
||
<p>This is similar to the <code>StreamExt::inspect</code> method where it allows
|
||
easily inspecting the success value as it passes through the stream, for
|
||
example to debug what's going on.</p>
|
||
</div><h3 id="method.inspect_err" class="method"><code>pub fn <a href="#method.inspect_err" class="fnname">inspect_err</a><F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.InspectErr.html" title="struct futures::stream::InspectErr">InspectErr</a><Self, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>), </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#312-315" title="goto source code">[src]</a></h3><div class="docblock"><p>Do something with the error value of this stream, afterwards passing it on.</p>
|
||
<p>This is similar to the <code>StreamExt::inspect</code> method where it allows
|
||
easily inspecting the error value as it passes through the stream, for
|
||
example to debug what's going on.</p>
|
||
</div><h3 id="method.into_stream" class="method"><code>pub fn <a href="#method.into_stream" class="fnname">into_stream</a>(self) -> <a class="struct" href="../../futures/stream/struct.IntoStream.html" title="struct futures::stream::IntoStream">IntoStream</a><Self></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#341-343" title="goto source code">[src]</a></h3><div class="docblock"><p>Wraps a <a href="../../futures/stream/trait.TryStream.html" title="TryStream"><code>TryStream</code></a> into a type that implements
|
||
<a href="../../futures/stream/trait.Stream.html"><code>Stream</code></a></p>
|
||
<p><a href="../../futures/stream/trait.TryStream.html" title="TryStream"><code>TryStream</code></a>s currently do not implement the
|
||
<a href="../../futures/stream/trait.Stream.html"><code>Stream</code></a> trait because of limitations
|
||
of the compiler.</p>
|
||
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="ident">Stream</span>, <span class="ident">TryStream</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">fn</span> <span class="ident">make_try_stream</span>() <span class="op">-</span><span class="op">></span> <span class="kw">impl</span> <span class="ident">TryStream</span><span class="op"><</span><span class="prelude-val">Ok</span> <span class="op">=</span> <span class="ident">T</span>, <span class="ident">Error</span> <span class="op">=</span> <span class="ident">E</span><span class="op">></span> { <span class="comment">// ... }</span>
|
||
<span class="kw">fn</span> <span class="ident">take_stream</span>(<span class="ident">stream</span>: <span class="kw">impl</span> <span class="ident">Stream</span><span class="op"><</span><span class="ident">Item</span> <span class="op">=</span> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">T</span>, <span class="ident">E</span><span class="op">></span><span class="op">></span>) { <span class="comment">/* ... */</span> }
|
||
|
||
<span class="ident">take_stream</span>(<span class="ident">make_try_stream</span>().<span class="ident">into_stream</span>());</pre></div>
|
||
</div><h3 id="method.try_next" class="method"><code>pub fn <a href="#method.try_next" class="fnname">try_next</a>(&mut self) -> <a class="struct" href="../../futures/stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, St></h3><code class="content"><span class="where fmt-newline">impl<'_, St> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, St> <span class="where fmt-newline">where<br> St: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#368-370" title="goto source code">[src]</a></h3><div class="docblock"><p>Creates a future that attempts to resolve the next item in the stream.
|
||
If an error is encountered before the next item, the error is returned
|
||
instead.</p>
|
||
<p>This is similar to the <code>Stream::next</code> combinator, but returns a
|
||
<code>Result<Option<T>, E></code> rather than an <code>Option<Result<T, E>></code>, making
|
||
for easy use with the <code>?</code> operator.</p>
|
||
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(()), <span class="prelude-val">Err</span>(())]);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">try_next</span>().<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(())));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">try_next</span>().<span class="kw">await</span>, <span class="prelude-val">Err</span>(()));</pre></div>
|
||
</div><h3 id="method.try_for_each" class="method"><code>pub fn <a href="#method.try_for_each" class="fnname">try_for_each</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><St, Fut, F></h3><code class="content"><span class="where fmt-newline">impl<St, Fut, F> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><St, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error = <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#408-412" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempts to run this stream to completion, executing the provided
|
||
asynchronous closure for each element on the stream.</p>
|
||
<p>The provided closure will be called for each item this stream produces,
|
||
yielding a future. That future will then be executed to completion
|
||
before moving on to the next item.</p>
|
||
<p>The returned value is a <a href="../../futures/future/trait.Future.html"><code>Future</code></a> where the
|
||
<a href="../../futures/future/trait.Future.html#associatedtype.Output"><code>Output</code></a> type is
|
||
<code>Result<(), Self::Error></code>. If any of the intermediate
|
||
futures or the stream returns an error, this future will return
|
||
immediately with an error.</p>
|
||
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">0i32</span>;
|
||
|
||
{
|
||
<span class="kw">let</span> <span class="ident">fut</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">repeat</span>(<span class="prelude-val">Ok</span>(<span class="number">1</span>)).<span class="ident">try_for_each</span>(<span class="op">|</span><span class="ident">item</span><span class="op">|</span> {
|
||
<span class="ident">x</span> <span class="op">+</span><span class="op">=</span> <span class="ident">item</span>;
|
||
<span class="ident">future</span>::<span class="ident">ready</span>(<span class="kw">if</span> <span class="ident">x</span> <span class="op">=</span><span class="op">=</span> <span class="number">3</span> { <span class="prelude-val">Err</span>(()) } <span class="kw">else</span> { <span class="prelude-val">Ok</span>(()) })
|
||
});
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">fut</span>.<span class="kw">await</span>, <span class="prelude-val">Err</span>(()));
|
||
}
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">x</span>, <span class="number">3</span>);</pre></div>
|
||
</div><h3 id="method.try_skip_while" class="method"><code>pub fn <a href="#method.try_skip_while" class="fnname">try_skip_while</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TrySkipWhile.html" title="struct futures::stream::TrySkipWhile">TrySkipWhile</a><Self, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#438-442" title="goto source code">[src]</a></h3><div class="docblock"><p>Skip elements on this stream while the provided asynchronous predicate
|
||
resolves to <code>true</code>.</p>
|
||
<p>This function is similar to
|
||
<a href="../../futures/stream/trait.StreamExt.html#method.skip_while"><code>StreamExt::skip_while</code></a> but exits
|
||
early if an error occurs.</p>
|
||
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>::<span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span>(<span class="number">1</span>), <span class="prelude-val">Ok</span>(<span class="number">3</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>)]);
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">try_skip_while</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">future</span>::<span class="ident">ready</span>(<span class="prelude-val">Ok</span>(<span class="kw-2">*</span><span class="ident">x</span> <span class="op"><</span> <span class="number">3</span>)));
|
||
|
||
<span class="kw">let</span> <span class="ident">output</span>: <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">try_collect</span>().<span class="kw">await</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">output</span>, <span class="prelude-val">Ok</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">3</span>, <span class="number">2</span>]));</pre></div>
|
||
</div><h3 id="method.try_take_while" class="method"><code>pub fn <a href="#method.try_take_while" class="fnname">try_take_while</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TryTakeWhile.html" title="struct futures::stream::TryTakeWhile">TryTakeWhile</a><Self, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#468-472" title="goto source code">[src]</a></h3><div class="docblock"><p>Take elements on this stream while the provided asynchronous predicate
|
||
resolves to <code>true</code>.</p>
|
||
<p>This function is similar to
|
||
<a href="../../futures/stream/trait.StreamExt.html#method.take_while"><code>StreamExt::take_while</code></a> but exits
|
||
early if an error occurs.</p>
|
||
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>::<span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span>(<span class="number">1</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>), <span class="prelude-val">Ok</span>(<span class="number">3</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>)]);
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">try_take_while</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">future</span>::<span class="ident">ready</span>(<span class="prelude-val">Ok</span>(<span class="kw-2">*</span><span class="ident">x</span> <span class="op"><</span> <span class="number">3</span>)));
|
||
|
||
<span class="kw">let</span> <span class="ident">output</span>: <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">try_collect</span>().<span class="kw">await</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">output</span>, <span class="prelude-val">Ok</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>]));</pre></div>
|
||
</div><h3 id="method.try_for_each_concurrent" class="method"><code>pub fn <a href="#method.try_for_each_concurrent" class="fnname">try_for_each_concurrent</a><Fut, F>(<br> self, <br> limit: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>>>, <br> f: F<br>) -> <a class="struct" href="../../futures/stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><St, Fut, F></h3><code class="content"><span class="where fmt-newline">impl<St, Fut, F> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><St, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a><Output = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>>,<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a><Output = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#520-528" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempts to run this stream to completion, executing the provided asynchronous
|
||
closure for each element on the stream concurrently as elements become
|
||
available, exiting as soon as an error occurs.</p>
|
||
<p>This is similar to
|
||
<a href="../../futures/stream/trait.StreamExt.html#method.for_each_concurrent"><code>StreamExt::for_each_concurrent</code></a>,
|
||
but will resolve to an error immediately if the underlying stream or the provided
|
||
closure return an error.</p>
|
||
<p>This method is only available when the <code>std</code> or <code>alloc</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
<h1 id="examples-9" class="section-header"><a href="#examples-9">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">oneshot</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">StreamExt</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> (<span class="ident">tx1</span>, <span class="ident">rx1</span>) <span class="op">=</span> <span class="ident">oneshot</span>::<span class="ident">channel</span>();
|
||
<span class="kw">let</span> (<span class="ident">tx2</span>, <span class="ident">rx2</span>) <span class="op">=</span> <span class="ident">oneshot</span>::<span class="ident">channel</span>();
|
||
<span class="kw">let</span> (<span class="ident">_tx3</span>, <span class="ident">rx3</span>) <span class="op">=</span> <span class="ident">oneshot</span>::<span class="ident">channel</span>();
|
||
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="ident">rx1</span>, <span class="ident">rx2</span>, <span class="ident">rx3</span>]);
|
||
<span class="kw">let</span> <span class="ident">fut</span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">map</span>(<span class="prelude-val">Ok</span>).<span class="ident">try_for_each_concurrent</span>(
|
||
<span class="comment">/* limit */</span> <span class="number">2</span>,
|
||
<span class="op">|</span><span class="ident">rx</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
|
||
<span class="kw">let</span> <span class="ident">res</span>: <span class="prelude-ty">Result</span><span class="op"><</span>(), <span class="ident">oneshot</span>::<span class="ident">Canceled</span><span class="op">></span> <span class="op">=</span> <span class="ident">rx</span>.<span class="kw">await</span>;
|
||
<span class="ident">res</span>
|
||
}
|
||
);
|
||
|
||
<span class="ident">tx1</span>.<span class="ident">send</span>(()).<span class="ident">unwrap</span>();
|
||
<span class="comment">// Drop the second sender so that `rx2` resolves to `Canceled`.</span>
|
||
<span class="ident">drop</span>(<span class="ident">tx2</span>);
|
||
|
||
<span class="comment">// The final result is an error because the second future</span>
|
||
<span class="comment">// resulted in an error.</span>
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Err</span>(<span class="ident">oneshot</span>::<span class="ident">Canceled</span>), <span class="ident">fut</span>.<span class="kw">await</span>);</pre></div>
|
||
</div><h3 id="method.try_collect" class="method"><code>pub fn <a href="#method.try_collect" class="fnname">try_collect</a><C>(self) -> <a class="struct" href="../../futures/stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><Self, C><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><St, C></h3><code class="content"><span class="where fmt-newline">impl<St, C> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><St, C> <span class="where fmt-newline">where<br> C: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>,<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><C, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> C: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#567-569" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempt to transform a stream into a collection,
|
||
returning a future representing the result of that computation.</p>
|
||
<p>This combinator will collect all successful results of this stream and
|
||
collect them into the specified collection type. If an error happens then all
|
||
collected elements will be dropped and the error will be returned.</p>
|
||
<p>The returned future will be resolved when the stream terminates.</p>
|
||
<h1 id="examples-10" class="section-header"><a href="#examples-10">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">mpsc</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::<span class="ident">TryStreamExt</span>;
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;
|
||
|
||
<span class="kw">let</span> (<span class="ident">tx</span>, <span class="ident">rx</span>) <span class="op">=</span> <span class="ident">mpsc</span>::<span class="ident">unbounded</span>();
|
||
|
||
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
|
||
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">1</span>..<span class="op">=</span><span class="number">5</span> {
|
||
<span class="ident">tx</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Ok</span>(<span class="ident">i</span>)).<span class="ident">unwrap</span>();
|
||
}
|
||
<span class="ident">tx</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Err</span>(<span class="number">6</span>)).<span class="ident">unwrap</span>();
|
||
});
|
||
|
||
<span class="kw">let</span> <span class="ident">output</span>: <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">rx</span>.<span class="ident">try_collect</span>().<span class="kw">await</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">output</span>, <span class="prelude-val">Err</span>(<span class="number">6</span>));</pre></div>
|
||
</div><h3 id="method.try_filter" class="method"><code>pub fn <a href="#method.try_filter" class="fnname">try_filter</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TryFilter.html" title="struct futures::stream::TryFilter">TryFilter</a><Self, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a><Output = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#604-608" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempt to filter the values produced by this stream according to the
|
||
provided asynchronous closure.</p>
|
||
<p>As values of this stream are made available, the provided predicate <code>f</code>
|
||
will be run on them. If the predicate returns a <code>Future</code> which resolves
|
||
to <code>true</code>, then the stream will yield the value, but if the predicate
|
||
return a <code>Future</code> which resolves to <code>false</code>, then the value will be
|
||
discarded and the next value will be produced.</p>
|
||
<p>All errors are passed through without filtering in this combinator.</p>
|
||
<p>Note that this function consumes the stream passed into it and returns a
|
||
wrapped version of it, similar to the existing <code>filter</code> methods in
|
||
the standard library.</p>
|
||
<h1 id="examples-11" class="section-header"><a href="#examples-11">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">StreamExt</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(<span class="number">1i32</span>), <span class="prelude-val">Ok</span>(<span class="number">2i32</span>), <span class="prelude-val">Ok</span>(<span class="number">3i32</span>), <span class="prelude-val">Err</span>(<span class="string">"error"</span>)]);
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">evens</span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">try_filter</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> {
|
||
<span class="ident">future</span>::<span class="ident">ready</span>(<span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span>)
|
||
});
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">evens</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">2</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">evens</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="string">"error"</span>)));</pre></div>
|
||
</div><h3 id="method.try_filter_map" class="method"><code>pub fn <a href="#method.try_filter_map" class="fnname">try_filter_map</a><Fut, F, T>(self, f: F) -> <a class="struct" href="../../futures/stream/struct.TryFilterMap.html" title="struct futures::stream::TryFilterMap">TryFilterMap</a><Self, Fut, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#645-649" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempt to filter the values produced by this stream while
|
||
simultaneously mapping them to a different type according to the
|
||
provided asynchronous closure.</p>
|
||
<p>As values of this stream are made available, the provided function will
|
||
be run on them. If the future returned by the predicate <code>f</code> resolves to
|
||
<a href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.Some"><code>Some(item)</code></a> then the stream will yield the value <code>item</code>, but if
|
||
it resolves to <a href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.None" title="None"><code>None</code></a> then the next value will be produced.</p>
|
||
<p>All errors are passed through without filtering in this combinator.</p>
|
||
<p>Note that this function consumes the stream passed into it and returns a
|
||
wrapped version of it, similar to the existing <code>filter_map</code> methods in
|
||
the standard library.</p>
|
||
<h1 id="examples-12" class="section-header"><a href="#examples-12">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">StreamExt</span>, <span class="ident">TryStreamExt</span>};
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">pin_mut</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(<span class="number">1i32</span>), <span class="prelude-val">Ok</span>(<span class="number">6i32</span>), <span class="prelude-val">Err</span>(<span class="string">"error"</span>)]);
|
||
<span class="kw">let</span> <span class="ident">halves</span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">try_filter_map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
|
||
<span class="kw">let</span> <span class="ident">ret</span> <span class="op">=</span> <span class="kw">if</span> <span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span> { <span class="prelude-val">Some</span>(<span class="ident">x</span> <span class="op">/</span> <span class="number">2</span>) } <span class="kw">else</span> { <span class="prelude-val">None</span> };
|
||
<span class="prelude-val">Ok</span>(<span class="ident">ret</span>)
|
||
});
|
||
|
||
<span class="macro">pin_mut</span><span class="macro">!</span>(<span class="ident">halves</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">halves</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">3</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">halves</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="string">"error"</span>)));</pre></div>
|
||
</div><h3 id="method.try_flatten" class="method"><code>pub fn <a href="#method.try_flatten" class="fnname">try_flatten</a>(self) -> <a class="struct" href="../../futures/stream/struct.TryFlatten.html" title="struct futures::stream::TryFlatten">TryFlatten</a><Self> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<br> <Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#692-696" title="goto source code">[src]</a></h3><div class="docblock"><p>Flattens a stream of streams into just one continuous stream.</p>
|
||
<p>If this stream's elements are themselves streams then this combinator
|
||
will flatten out the entire stream to one long chain of elements. Any
|
||
errors are passed through without looking at them, but otherwise each
|
||
individual stream will get exhausted before moving on to the next.</p>
|
||
<h1 id="examples-13" class="section-header"><a href="#examples-13">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">mpsc</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="ident">StreamExt</span>, <span class="ident">TryStreamExt</span>};
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;
|
||
|
||
<span class="kw">let</span> (<span class="ident">tx1</span>, <span class="ident">rx1</span>) <span class="op">=</span> <span class="ident">mpsc</span>::<span class="ident">unbounded</span>();
|
||
<span class="kw">let</span> (<span class="ident">tx2</span>, <span class="ident">rx2</span>) <span class="op">=</span> <span class="ident">mpsc</span>::<span class="ident">unbounded</span>();
|
||
<span class="kw">let</span> (<span class="ident">tx3</span>, <span class="ident">rx3</span>) <span class="op">=</span> <span class="ident">mpsc</span>::<span class="ident">unbounded</span>();
|
||
|
||
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
|
||
<span class="ident">tx1</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Ok</span>(<span class="number">1</span>)).<span class="ident">unwrap</span>();
|
||
});
|
||
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
|
||
<span class="ident">tx2</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Ok</span>(<span class="number">2</span>)).<span class="ident">unwrap</span>();
|
||
<span class="ident">tx2</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Err</span>(<span class="number">3</span>)).<span class="ident">unwrap</span>();
|
||
});
|
||
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
|
||
<span class="ident">tx3</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Ok</span>(<span class="ident">rx1</span>)).<span class="ident">unwrap</span>();
|
||
<span class="ident">tx3</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Ok</span>(<span class="ident">rx2</span>)).<span class="ident">unwrap</span>();
|
||
<span class="ident">tx3</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Err</span>(<span class="number">4</span>)).<span class="ident">unwrap</span>();
|
||
});
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">rx3</span>.<span class="ident">try_flatten</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">1</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">2</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">stream</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="number">3</span>)));</pre></div>
|
||
</div><h3 id="method.try_fold" class="method"><code>pub fn <a href="#method.try_fold" class="fnname">try_fold</a><T, Fut, F>(self, init: T, f: F) -> <a class="struct" href="../../futures/stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><Self, Fut, T, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><St, Fut, T, F></h3><code class="content"><span class="where fmt-newline">impl<St, Fut, T, F> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><St, Fut, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = T, Error = <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T, Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = T, Error = Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#731-735" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempt to execute an accumulating asynchronous computation over a
|
||
stream, collecting all the values into one final result.</p>
|
||
<p>This combinator will accumulate all values returned by this stream
|
||
according to the closure provided. The initial state is also provided to
|
||
this method and then is returned again by each execution of the closure.
|
||
Once the entire stream has been exhausted the returned future will
|
||
resolve to this value.</p>
|
||
<p>This method is similar to <a href="../../futures/stream/trait.StreamExt.html#method.fold"><code>fold</code></a>, but will
|
||
exit early if an error is encountered in either the stream or the
|
||
provided closure.</p>
|
||
<h1 id="examples-14" class="section-header"><a href="#examples-14">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">number_stream</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>::<span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span>(<span class="number">1</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>)]);
|
||
<span class="kw">let</span> <span class="ident">sum</span> <span class="op">=</span> <span class="ident">number_stream</span>.<span class="ident">try_fold</span>(<span class="number">0</span>, <span class="op">|</span><span class="ident">acc</span>, <span class="ident">x</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> { <span class="prelude-val">Ok</span>(<span class="ident">acc</span> <span class="op">+</span> <span class="ident">x</span>) });
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum</span>.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="number">3</span>));
|
||
|
||
<span class="kw">let</span> <span class="ident">number_stream_with_err</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>::<span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span>(<span class="number">1</span>), <span class="prelude-val">Err</span>(<span class="number">2</span>), <span class="prelude-val">Ok</span>(<span class="number">1</span>)]);
|
||
<span class="kw">let</span> <span class="ident">sum</span> <span class="op">=</span> <span class="ident">number_stream_with_err</span>.<span class="ident">try_fold</span>(<span class="number">0</span>, <span class="op">|</span><span class="ident">acc</span>, <span class="ident">x</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> { <span class="prelude-val">Ok</span>(<span class="ident">acc</span> <span class="op">+</span> <span class="ident">x</span>) });
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum</span>.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">2</span>));</pre></div>
|
||
</div><h3 id="method.try_concat" class="method"><code>pub fn <a href="#method.try_concat" class="fnname">try_concat</a>(self) -> <a class="struct" href="../../futures/stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures/stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><St></h3><code class="content"><span class="where fmt-newline">impl<St> <a class="trait" href="../../futures/future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../futures/stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><St> <span class="where fmt-newline">where<br> St: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<br> <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>>,<br> <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,<br> <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a>, </span></span><span class="where fmt-newline"> type <a href="../../futures/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>, <St as <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" title="type core::iter::traits::collect::IntoIterator::Item">Item</a>>,<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>,<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#774-777" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempt to concatenate all items of a stream into a single
|
||
extendable destination, returning a future representing the end result.</p>
|
||
<p>This combinator will extend the first item with the contents of all
|
||
the subsequent successful results of the stream. If the stream is empty,
|
||
the default value will be returned.</p>
|
||
<p>Works with all collections that implement the <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html"><code>Extend</code></a> trait.</p>
|
||
<p>This method is similar to <a href="../../futures/stream/trait.StreamExt.html#method.concat"><code>concat</code></a>, but will
|
||
exit early if an error is encountered in the stream.</p>
|
||
<h1 id="examples-15" class="section-header"><a href="#examples-15">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">mpsc</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::<span class="ident">TryStreamExt</span>;
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;
|
||
|
||
<span class="kw">let</span> (<span class="ident">tx</span>, <span class="ident">rx</span>) <span class="op">=</span> <span class="ident">mpsc</span>::<span class="ident">unbounded</span>::<span class="op"><</span><span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span>, ()<span class="op">></span><span class="op">></span>();
|
||
|
||
<span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
|
||
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> (<span class="number">0</span>..<span class="number">3</span>).<span class="ident">rev</span>() {
|
||
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="ident">i</span> <span class="op">*</span> <span class="number">3</span>;
|
||
<span class="ident">tx</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Ok</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="ident">n</span> <span class="op">+</span> <span class="number">1</span>, <span class="ident">n</span> <span class="op">+</span> <span class="number">2</span>, <span class="ident">n</span> <span class="op">+</span> <span class="number">3</span>])).<span class="ident">unwrap</span>();
|
||
}
|
||
});
|
||
|
||
<span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">rx</span>.<span class="ident">try_concat</span>().<span class="kw">await</span>;
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">result</span>, <span class="prelude-val">Ok</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]));</pre></div>
|
||
</div><h3 id="method.try_buffer_unordered" class="method"><code>pub fn <a href="#method.try_buffer_unordered" class="fnname">try_buffer_unordered</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../futures/stream/struct.TryBufferUnordered.html" title="struct futures::stream::TryBufferUnordered">TryBufferUnordered</a><Self> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>,<br> <Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>>::<a class="type" href="../../futures/future/trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a> == Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#841-844" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempt to execute several futures from a stream concurrently (unordered).</p>
|
||
<p>This stream's <code>Ok</code> type must be a <a href="../../futures/future/trait.TryFuture.html"><code>TryFuture</code></a> with an <code>Error</code> type
|
||
that matches the stream's <code>Error</code> type.</p>
|
||
<p>This adaptor will buffer up to <code>n</code> futures and then return their
|
||
outputs in the order in which they complete. If the underlying stream
|
||
returns an error, it will be immediately propagated.</p>
|
||
<p>The returned stream will be a stream of results, each containing either
|
||
an error or a future's output. An error can be produced either by the
|
||
underlying stream itself or by one of the futures it yielded.</p>
|
||
<p>This method is only available when the <code>std</code> or <code>alloc</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
<h1 id="examples-16" class="section-header"><a href="#examples-16">Examples</a></h1>
|
||
<p>Results are returned in the order of completion:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">oneshot</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">StreamExt</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> (<span class="ident">send_one</span>, <span class="ident">recv_one</span>) <span class="op">=</span> <span class="ident">oneshot</span>::<span class="ident">channel</span>();
|
||
<span class="kw">let</span> (<span class="ident">send_two</span>, <span class="ident">recv_two</span>) <span class="op">=</span> <span class="ident">oneshot</span>::<span class="ident">channel</span>();
|
||
|
||
<span class="kw">let</span> <span class="ident">stream_of_futures</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(<span class="ident">recv_one</span>), <span class="prelude-val">Ok</span>(<span class="ident">recv_two</span>)]);
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffered</span> <span class="op">=</span> <span class="ident">stream_of_futures</span>.<span class="ident">try_buffer_unordered</span>(<span class="number">10</span>);
|
||
|
||
<span class="ident">send_two</span>.<span class="ident">send</span>(<span class="number">2i32</span>)<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">2i32</span>)));
|
||
|
||
<span class="ident">send_one</span>.<span class="ident">send</span>(<span class="number">1i32</span>)<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">1i32</span>)));
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">None</span>);</pre></div>
|
||
<p>Errors from the underlying stream itself are propagated:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">mpsc</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="ident">StreamExt</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> (<span class="ident">sink</span>, <span class="ident">stream_of_futures</span>) <span class="op">=</span> <span class="ident">mpsc</span>::<span class="ident">unbounded</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffered</span> <span class="op">=</span> <span class="ident">stream_of_futures</span>.<span class="ident">try_buffer_unordered</span>(<span class="number">10</span>);
|
||
|
||
<span class="ident">sink</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Ok</span>(<span class="kw">async</span> { <span class="prelude-val">Ok</span>(<span class="number">7i32</span>) }))<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">7i32</span>)));
|
||
|
||
<span class="ident">sink</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Err</span>(<span class="string">"error in the stream"</span>))<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="string">"error in the stream"</span>)));</pre></div>
|
||
</div><h3 id="method.try_buffered" class="method"><code>pub fn <a href="#method.try_buffered" class="fnname">try_buffered</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../futures/stream/struct.TryBuffered.html" title="struct futures::stream::TryBuffered">TryBuffered</a><Self> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>,<br> <Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../futures/future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>>::<a class="type" href="../../futures/future/trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a> == Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#917-920" title="goto source code">[src]</a></h3><div class="docblock"><p>Attempt to execute several futures from a stream concurrently.</p>
|
||
<p>This stream's <code>Ok</code> type must be a <a href="../../futures/future/trait.TryFuture.html"><code>TryFuture</code></a> with an <code>Error</code> type
|
||
that matches the stream's <code>Error</code> type.</p>
|
||
<p>This adaptor will buffer up to <code>n</code> futures and then return their
|
||
outputs in the order. If the underlying stream returns an error, it will
|
||
be immediately propagated.</p>
|
||
<p>The returned stream will be a stream of results, each containing either
|
||
an error or a future's output. An error can be produced either by the
|
||
underlying stream itself or by one of the futures it yielded.</p>
|
||
<p>This method is only available when the <code>std</code> or <code>alloc</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
<h1 id="examples-17" class="section-header"><a href="#examples-17">Examples</a></h1>
|
||
<p>Results are returned in the order of addition:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">oneshot</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">lazy</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">StreamExt</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> (<span class="ident">send_one</span>, <span class="ident">recv_one</span>) <span class="op">=</span> <span class="ident">oneshot</span>::<span class="ident">channel</span>();
|
||
<span class="kw">let</span> (<span class="ident">send_two</span>, <span class="ident">recv_two</span>) <span class="op">=</span> <span class="ident">oneshot</span>::<span class="ident">channel</span>();
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffered</span> <span class="op">=</span> <span class="ident">lazy</span>(<span class="kw">move</span> <span class="op">|</span><span class="ident">cx</span><span class="op">|</span> {
|
||
<span class="kw">let</span> <span class="ident">stream_of_futures</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(<span class="ident">recv_one</span>), <span class="prelude-val">Ok</span>(<span class="ident">recv_two</span>)]);
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffered</span> <span class="op">=</span> <span class="ident">stream_of_futures</span>.<span class="ident">try_buffered</span>(<span class="number">10</span>);
|
||
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">try_poll_next_unpin</span>(<span class="ident">cx</span>).<span class="ident">is_pending</span>());
|
||
|
||
<span class="ident">send_two</span>.<span class="ident">send</span>(<span class="number">2i32</span>)<span class="question-mark">?</span>;
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">try_poll_next_unpin</span>(<span class="ident">cx</span>).<span class="ident">is_pending</span>());
|
||
<span class="prelude-val">Ok</span>::<span class="op"><</span><span class="kw">_</span>, <span class="ident">i32</span><span class="op">></span>(<span class="ident">buffered</span>)
|
||
}).<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="ident">send_one</span>.<span class="ident">send</span>(<span class="number">1i32</span>)<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">1i32</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">2i32</span>)));
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">None</span>);</pre></div>
|
||
<p>Errors from the underlying stream itself are propagated:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">channel</span>::<span class="ident">mpsc</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="ident">StreamExt</span>, <span class="ident">TryStreamExt</span>};
|
||
|
||
<span class="kw">let</span> (<span class="ident">sink</span>, <span class="ident">stream_of_futures</span>) <span class="op">=</span> <span class="ident">mpsc</span>::<span class="ident">unbounded</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffered</span> <span class="op">=</span> <span class="ident">stream_of_futures</span>.<span class="ident">try_buffered</span>(<span class="number">10</span>);
|
||
|
||
<span class="ident">sink</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Ok</span>(<span class="kw">async</span> { <span class="prelude-val">Ok</span>(<span class="number">7i32</span>) }))<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">7i32</span>)));
|
||
|
||
<span class="ident">sink</span>.<span class="ident">unbounded_send</span>(<span class="prelude-val">Err</span>(<span class="string">"error in the stream"</span>))<span class="question-mark">?</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buffered</span>.<span class="ident">next</span>().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="string">"error in the stream"</span>)));</pre></div>
|
||
</div><h3 id="method.try_poll_next_unpin" class="method"><code>pub fn <a href="#method.try_poll_next_unpin" class="fnname">try_poll_next_unpin</a>(<br> &mut self, <br> cx: &mut <a class="struct" href="../../futures/task/struct.Context.html" title="struct futures::task::Context">Context</a><'_><br>) -> <a class="enum" href="../../futures/task/enum.Poll.html" title="enum futures::task::Poll">Poll</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>, Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>>> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#929-934" title="goto source code">[src]</a></h3><div class="docblock"><p>A convenience method for calling <a href="../../futures/stream/trait.TryStream.html#tymethod.try_poll_next" title="TryStream::try_poll_next"><code>TryStream::try_poll_next</code></a> on <a href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="Unpin"><code>Unpin</code></a>
|
||
stream types.</p>
|
||
</div><h3 id="method.into_async_read" class="method"><code>pub fn <a href="#method.into_async_read" class="fnname">into_async_read</a>(self) -> <a class="struct" href="../../futures/stream/struct.IntoAsyncRead.html" title="struct futures::stream::IntoAsyncRead">IntoAsyncRead</a><Self> <span class="where fmt-newline">where<br> Self: <a class="trait" href="../../futures/stream/trait.TryStreamExt.html" title="trait futures::stream::TryStreamExt">TryStreamExt</a><Error = <a class="struct" href="../../futures/io/struct.Error.html" title="struct futures::io::Error">Error</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> Self::<a class="type" href="../../futures/stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>>, </span></code><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#995-998" title="goto source code">[src]</a></h3><div class="docblock"><p>Adapter that converts this stream into an <a href="../../futures/io/trait.AsyncRead.html"><code>AsyncRead</code></a>.</p>
|
||
<p>Note that because <code>into_async_read</code> moves the stream, the <a href="../../futures/stream/trait.Stream.html"><code>Stream</code></a> type must be
|
||
<a href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="Unpin"><code>Unpin</code></a>. If you want to use <code>into_async_read</code> with a <a href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"><code>!Unpin</code></a> stream, you'll
|
||
first have to pin the stream. This can be done by boxing the stream using <a href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html#method.pin" title="Box::pin"><code>Box::pin</code></a>
|
||
or pinning it to the stack using the <code>pin_mut!</code> macro from the <code>pin_utils</code> crate.</p>
|
||
<p>This method is only available when the <code>std</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
<h1 id="examples-18" class="section-header"><a href="#examples-18">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">TryStreamExt</span>};
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">io</span>::<span class="ident">AsyncReadExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="prelude-val">Ok</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>])]);
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">reader</span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">into_async_read</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buf</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
|
||
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">reader</span>.<span class="ident">read_to_end</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">buf</span>).<span class="kw">await</span>.<span class="ident">is_ok</span>());
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buf</span>, <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>]);</pre></div>
|
||
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-TryStreamExt" class="impl"><code class="in-band">impl<S> TryStreamExt for S <span class="where fmt-newline">where<br> S: <a class="trait" href="../../futures/stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href="#impl-TryStreamExt" class="anchor"></a><a class="srclink" href="../../src/futures_util/stream/try_stream/mod.rs.html#141" title="goto source code">[src]</a></h3><div class="impl-items"></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/futures_util/stream/try_stream/trait.TryStreamExt.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="futures"></div>
|
||
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html> |