| <!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="Adapters specific to `Result`-returning streams"><meta name="keywords" content="rust, rustlang, rust-lang, TryStreamExt"><title>TryStreamExt in futures::prelude::stream - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../normalize.css"><link rel="stylesheet" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../ayu.css" disabled><link rel="stylesheet" href="../../../dark.css" disabled><link rel="stylesheet" href="../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../main.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../../futures/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../futures/index.html"><div class="logo-container"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">TryStreamExt</a></h2><div class="sidebar-elems"><section><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.and_then">and_then</a></li><li><a href="#method.err_into">err_into</a></li><li><a href="#method.inspect_err">inspect_err</a></li><li><a href="#method.inspect_ok">inspect_ok</a></li><li><a href="#method.into_async_read">into_async_read</a></li><li><a href="#method.into_stream">into_stream</a></li><li><a href="#method.map_err">map_err</a></li><li><a href="#method.map_ok">map_ok</a></li><li><a href="#method.or_else">or_else</a></li><li><a href="#method.try_buffer_unordered">try_buffer_unordered</a></li><li><a href="#method.try_buffered">try_buffered</a></li><li><a href="#method.try_chunks">try_chunks</a></li><li><a href="#method.try_collect">try_collect</a></li><li><a href="#method.try_concat">try_concat</a></li><li><a href="#method.try_filter">try_filter</a></li><li><a href="#method.try_filter_map">try_filter_map</a></li><li><a href="#method.try_flatten">try_flatten</a></li><li><a href="#method.try_flatten_unordered">try_flatten_unordered</a></li><li><a href="#method.try_fold">try_fold</a></li><li><a href="#method.try_for_each">try_for_each</a></li><li><a href="#method.try_for_each_concurrent">try_for_each_concurrent</a></li><li><a href="#method.try_next">try_next</a></li><li><a href="#method.try_poll_next_unpin">try_poll_next_unpin</a></li><li><a href="#method.try_skip_while">try_skip_while</a></li><li><a href="#method.try_take_while">try_take_while</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In futures::prelude::stream</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Trait <a href="../../index.html">futures</a>::<wbr><a href="../index.html">prelude</a>::<wbr><a href="index.html">stream</a>::<wbr><a class="trait" href="#">TryStreamExt</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../../src/futures_util/stream/try_stream/mod.rs.html#166">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait TryStreamExt: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a> { |
| <details class="rustdoc-toggle type-contents-toggle"><summary class="hideme"><span>Show 25 methods</span></summary> fn <a href="#method.err_into" class="fnname">err_into</a><E>(self) -> <a class="struct" href="../../stream/struct.ErrInto.html" title="struct futures::stream::ErrInto">ErrInto</a><Self, E><br> <span class="where">where<br> Self::<a class="associatedtype" href="../../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>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.map_ok" class="fnname">map_ok</a><T, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> T</span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.map_err" class="fnname">map_err</a><E, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>) -> E</span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.and_then" class="fnname">and_then</a><Fut, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.or_else" class="fnname">or_else</a><Fut, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>) -> Fut,<br> Fut: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.inspect_ok" class="fnname">inspect_ok</a><F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>)</span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.inspect_err" class="fnname">inspect_err</a><F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>)</span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.into_stream" class="fnname">into_stream</a>(self) -> <a class="struct" href="../../stream/struct.IntoStream.html" title="struct futures::stream::IntoStream">IntoStream</a><Self> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_next" class="fnname">try_next</a>(&mut self) -> <a class="struct" href="../../stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, St></span><code class="content"><span class="where fmt-newline">impl<St> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, St><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a> + <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="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="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>, <St as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_for_each" class="fnname">try_for_each</a><Fut, F>(self, f: F) -> <a class="struct" href="../../stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><St, Fut, F></span><code class="content"><span class="where fmt-newline">impl<St, Fut, F> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><St, Fut, F><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></span><span class="where fmt-newline"> type <a href="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_skip_while" class="fnname">try_skip_while</a><Fut, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_take_while" class="fnname">try_take_while</a><Fut, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> 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="../../stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><St, Fut, F></span><code class="content"><span class="where fmt-newline">impl<St, Fut, F> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><St, Fut, F><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>>,</span></span><span class="where fmt-newline"> type <a href="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_collect" class="fnname">try_collect</a><C>(self) -> <a class="struct" href="../../stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><Self, C><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><St, C></span><code class="content"><span class="where fmt-newline">impl<St, C> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><St, C><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>,</span></span><span class="where fmt-newline"> type <a href="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_chunks" class="fnname">try_chunks</a>(self, capacity: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../stream/struct.TryChunks.html" title="struct futures::stream::TryChunks">TryChunks</a><Self> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_filter" class="fnname">try_filter</a><Fut, F>(self, f: F) -> <a class="struct" href="../../stream/struct.TryFilter.html" title="struct futures::stream::TryFilter">TryFilter</a><Self, Fut, F><br> <span class="where">where<br> Fut: <a class="trait" href="../../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>>,<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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut</span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_filter_map" class="fnname">try_filter_map</a><Fut, F, T>(self, f: F) -> <a class="struct" href="../../stream/struct.TryFilterMap.html" title="struct futures::stream::TryFilterMap">TryFilterMap</a><Self, Fut, F><br> <span class="where">where<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,<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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut</span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_flatten_unordered" class="fnname">try_flatten_unordered</a>(<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> ) -> <a class="struct" href="../../stream/struct.TryFlattenUnordered.html" title="struct futures::stream::TryFlattenUnordered">TryFlattenUnordered</a><Self><br> <span class="where">where<br> Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_flatten" class="fnname">try_flatten</a>(self) -> <a class="struct" href="../../stream/struct.TryFlatten.html" title="struct futures::stream::TryFlatten">TryFlatten</a><Self><br> <span class="where">where<br> Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<br> <Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_fold" class="fnname">try_fold</a><T, Fut, F>(self, init: T, f: F) -> <a class="struct" href="../../stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><Self, Fut, T, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><St, Fut, T, F></span><code class="content"><span class="where fmt-newline">impl<St, Fut, T, F> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><St, Fut, T, F><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = T, Error = <St as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></span><span class="where fmt-newline"> type <a href="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = T, Error = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_concat" class="fnname">try_concat</a>(self) -> <a class="struct" href="../../stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><St></span><code class="content"><span class="where fmt-newline">impl<St> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><St><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<br> <St as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../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="associatedtype" 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>> + <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="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="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>, <St as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></span></span><br> <span class="where">where<br> Self::<a class="associatedtype" href="../../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="associatedtype" href="../../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="associatedtype" 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>> + <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="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a></span>, |
| { ... } |
| <span class="item-spacer"></span> 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="../../stream/struct.TryBufferUnordered.html" title="struct futures::stream::TryBufferUnordered">TryBufferUnordered</a><Self><br> <span class="where">where<br> Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> 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="../../stream/struct.TryBuffered.html" title="struct futures::stream::TryBuffered">TryBuffered</a><Self><br> <span class="where">where<br> Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> 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="../../task/struct.Context.html" title="struct futures::task::Context">Context</a><'_><br> ) -> <a class="enum" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>, Self::<a class="associatedtype" href="../../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>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.into_async_read" class="fnname">into_async_read</a>(self) -> <a class="struct" href="../../stream/struct.IntoAsyncRead.html" title="struct futures::stream::IntoAsyncRead">IntoAsyncRead</a><Self><br> <span class="where">where<br> Self: <a class="trait" href="../../stream/trait.TryStreamExt.html" title="trait futures::stream::TryStreamExt">TryStreamExt</a><Error = <a class="struct" href="../../io/struct.Error.html" title="struct futures::io::Error">Error</a>>,<br> Self::<a class="associatedtype" href="../../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.u8.html">u8</a>]></span>, |
| { ... } |
| </details>}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Adapters specific to <code>Result</code>-returning streams</p> |
| </div></details><h2 id="provided-methods" class="small-section-header">Provided Methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.err_into" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#184-187">source</a><h4 class="code-header">fn <a href="#method.err_into" class="fnname">err_into</a><E>(self) -> <a class="struct" href="../../stream/struct.ErrInto.html" title="struct futures::stream::ErrInto">ErrInto</a><Self, E><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="../../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></h4></section></summary><div class="docblock"><p>Wraps the current stream in a new stream which converts the error type |
| into the one provided.</p> |
| <h5 id="examples"><a href="#examples">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>stream = |
| stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(()), <span class="prelude-val">Err</span>(<span class="number">5i32</span>)]) |
| .err_into::<i64>(); |
| |
| <span class="macro">assert_eq!</span>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(()))); |
| <span class="macro">assert_eq!</span>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">5i64</span>));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.map_ok" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#209-212">source</a><h4 class="code-header">fn <a href="#method.map_ok" class="fnname">map_ok</a><T, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> T,</span></h4></section></summary><div class="docblock"><p>Wraps the current stream in a new stream which maps the success value |
| using the provided closure.</p> |
| <h5 id="examples-1"><a href="#examples-1">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>stream = |
| stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">5</span>), <span class="prelude-val">Err</span>(<span class="number">0</span>)]) |
| .map_ok(|x| x + <span class="number">2</span>); |
| |
| <span class="macro">assert_eq!</span>(stream.try_next().<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>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">0</span>));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.map_err" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#234-237">source</a><h4 class="code-header">fn <a href="#method.map_err" class="fnname">map_err</a><E, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>) -> E,</span></h4></section></summary><div class="docblock"><p>Wraps the current stream in a new stream which maps the error value |
| using the provided closure.</p> |
| <h5 id="examples-2"><a href="#examples-2">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>stream = |
| stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="number">5</span>), <span class="prelude-val">Err</span>(<span class="number">0</span>)]) |
| .map_err(|x| x + <span class="number">2</span>); |
| |
| <span class="macro">assert_eq!</span>(stream.try_next().<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>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">2</span>));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.and_then" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#280-284">source</a><h4 class="code-header">fn <a href="#method.and_then" class="fnname">and_then</a><Fut, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><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> |
| <h5 id="examples-3"><a href="#examples-3">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::mpsc; |
| <span class="kw">use </span>futures::future; |
| <span class="kw">use </span>futures::stream::TryStreamExt; |
| |
| <span class="kw">let </span>(_tx, rx) = mpsc::channel::<<span class="prelude-ty">Result</span><i32, ()>>(<span class="number">1</span>); |
| |
| <span class="kw">let </span>rx = rx.and_then(|result| { |
| future::ok(<span class="kw">if </span>result % <span class="number">2 </span>== <span class="number">0 </span>{ |
| <span class="prelude-val">Some</span>(result) |
| } <span class="kw">else </span>{ |
| <span class="prelude-val">None |
| </span>}) |
| });</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.or_else" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#306-310">source</a><h4 class="code-header">fn <a href="#method.or_else" class="fnname">or_else</a><Fut, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>) -> Fut,<br> Fut: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>,</span></h4></section></summary><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="../../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></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.inspect_ok" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#321-324">source</a><h4 class="code-header">fn <a href="#method.inspect_ok" class="fnname">inspect_ok</a><F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>),</span></h4></section></summary><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></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.inspect_err" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#334-337">source</a><h4 class="code-header">fn <a href="#method.inspect_err" class="fnname">inspect_err</a><F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>),</span></h4></section></summary><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></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_stream" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#363-365">source</a><h4 class="code-header">fn <a href="#method.into_stream" class="fnname">into_stream</a>(self) -> <a class="struct" href="../../stream/struct.IntoStream.html" title="struct futures::stream::IntoStream">IntoStream</a><Self></h4></section></summary><div class="docblock"><p>Wraps a <a href="../../stream/trait.TryStream.html" title="TryStream"><code>TryStream</code></a> into a type that implements |
| <a href="../../stream/trait.Stream.html"><code>Stream</code></a></p> |
| <p><a href="../../stream/trait.TryStream.html" title="TryStream"><code>TryStream</code></a>s currently do not implement the |
| <a href="../../stream/trait.Stream.html"><code>Stream</code></a> trait because of limitations |
| of the compiler.</p> |
| <h5 id="examples-4"><a href="#examples-4">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{Stream, TryStream, TryStreamExt}; |
| |
| <span class="kw">fn </span>make_try_stream() -> <span class="kw">impl </span>TryStream<<span class="prelude-val">Ok </span>= T, Error = E> { <span class="comment">// ... } |
| </span><span class="kw">fn </span>take_stream(stream: <span class="kw">impl </span>Stream<Item = <span class="prelude-ty">Result</span><T, E>>) { <span class="comment">/* ... */ </span>} |
| |
| take_stream(make_try_stream().into_stream());</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_next" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#390-392">source</a><h4 class="code-header">fn <a href="#method.try_next" class="fnname">try_next</a>(&mut self) -> <a class="struct" href="../../stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, St></span><code class="content"><span class="where fmt-newline">impl<St> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryNext.html" title="struct futures::stream::TryNext">TryNext</a><'_, St><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a> + <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="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="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>, <St as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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></h4></section></summary><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> |
| <h5 id="examples-5"><a href="#examples-5">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>stream = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(()), <span class="prelude-val">Err</span>(())]); |
| |
| <span class="macro">assert_eq!</span>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(()))); |
| <span class="macro">assert_eq!</span>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Err</span>(()));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_for_each" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#430-434">source</a><h4 class="code-header">fn <a href="#method.try_for_each" class="fnname">try_for_each</a><Fut, F>(self, f: F) -> <a class="struct" href="../../stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><St, Fut, F></span><code class="content"><span class="where fmt-newline">impl<St, Fut, F> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryForEach.html" title="struct futures::stream::TryForEach">TryForEach</a><St, Fut, F><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></span><span class="where fmt-newline"> type <a href="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><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="../../future/trait.Future.html"><code>Future</code></a> where the |
| <a href="../../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> |
| <h5 id="examples-6"><a href="#examples-6">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::future; |
| <span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>x = <span class="number">0i32</span>; |
| |
| { |
| <span class="kw">let </span>fut = stream::repeat(<span class="prelude-val">Ok</span>(<span class="number">1</span>)).try_for_each(|item| { |
| x += item; |
| future::ready(<span class="kw">if </span>x == <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>(fut.<span class="kw">await</span>, <span class="prelude-val">Err</span>(())); |
| } |
| |
| <span class="macro">assert_eq!</span>(x, <span class="number">3</span>);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_skip_while" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#460-464">source</a><h4 class="code-header">fn <a href="#method.try_skip_while" class="fnname">try_skip_while</a><Fut, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><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="../../stream/trait.StreamExt.html#method.skip_while"><code>StreamExt::skip_while</code></a> but exits |
| early if an error occurs.</p> |
| <h5 id="examples-7"><a href="#examples-7">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::future; |
| <span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span>stream = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>::<i32, i32>(<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>stream = stream.try_skip_while(|x| future::ready(<span class="prelude-val">Ok</span>(<span class="kw-2">*</span>x < <span class="number">3</span>))); |
| |
| <span class="kw">let </span>output: <span class="prelude-ty">Result</span><Vec<i32>, i32> = stream.try_collect().<span class="kw">await</span>; |
| <span class="macro">assert_eq!</span>(output, <span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[<span class="number">3</span>, <span class="number">2</span>]));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_take_while" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#490-494">source</a><h4 class="code-header">fn <a href="#method.try_take_while" class="fnname">try_take_while</a><Fut, F>(self, f: F) -> <a class="struct" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><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="../../stream/trait.StreamExt.html#method.take_while"><code>StreamExt::take_while</code></a> but exits |
| early if an error occurs.</p> |
| <h5 id="examples-8"><a href="#examples-8">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::future; |
| <span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span>stream = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>::<i32, i32>(<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>stream = stream.try_take_while(|x| future::ready(<span class="prelude-val">Ok</span>(<span class="kw-2">*</span>x < <span class="number">3</span>))); |
| |
| <span class="kw">let </span>output: <span class="prelude-ty">Result</span><Vec<i32>, i32> = stream.try_collect().<span class="kw">await</span>; |
| <span class="macro">assert_eq!</span>(output, <span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>]));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_for_each_concurrent" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#542-550">source</a><h4 class="code-header">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="../../stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><St, Fut, F></span><code class="content"><span class="where fmt-newline">impl<St, Fut, F> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryForEachConcurrent.html" title="struct futures::stream::TryForEachConcurrent">TryForEachConcurrent</a><St, Fut, F><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>>,</span></span><span class="where fmt-newline"> type <a href="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>>,</span></h4></section></summary><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="../../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> |
| <h5 id="examples-9"><a href="#examples-9">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::oneshot; |
| <span class="kw">use </span>futures::stream::{<span class="self">self</span>, StreamExt, TryStreamExt}; |
| |
| <span class="kw">let </span>(tx1, rx1) = oneshot::channel(); |
| <span class="kw">let </span>(tx2, rx2) = oneshot::channel(); |
| <span class="kw">let </span>(_tx3, rx3) = oneshot::channel(); |
| |
| <span class="kw">let </span>stream = stream::iter(<span class="macro">vec!</span>[rx1, rx2, rx3]); |
| <span class="kw">let </span>fut = stream.map(<span class="prelude-val">Ok</span>).try_for_each_concurrent( |
| <span class="comment">/* limit */ </span><span class="number">2</span>, |
| |rx| <span class="kw">async move </span>{ |
| <span class="kw">let </span>res: <span class="prelude-ty">Result</span><(), oneshot::Canceled> = rx.<span class="kw">await</span>; |
| res |
| } |
| ); |
| |
| tx1.send(()).unwrap(); |
| <span class="comment">// Drop the second sender so that `rx2` resolves to `Canceled`. |
| </span>drop(tx2); |
| |
| <span class="comment">// The final result is an error because the second future |
| // resulted in an error. |
| </span><span class="macro">assert_eq!</span>(<span class="prelude-val">Err</span>(oneshot::Canceled), fut.<span class="kw">await</span>);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_collect" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#589-591">source</a><h4 class="code-header">fn <a href="#method.try_collect" class="fnname">try_collect</a><C>(self) -> <a class="struct" href="../../stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><Self, C><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><St, C></span><code class="content"><span class="where fmt-newline">impl<St, C> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryCollect.html" title="struct futures::stream::TryCollect">TryCollect</a><St, C><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>,</span></span><span class="where fmt-newline"> type <a href="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>>,</span></h4></section></summary><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> |
| <h5 id="examples-10"><a href="#examples-10">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::mpsc; |
| <span class="kw">use </span>futures::stream::TryStreamExt; |
| <span class="kw">use </span>std::thread; |
| |
| <span class="kw">let </span>(tx, rx) = mpsc::unbounded(); |
| |
| thread::spawn(<span class="kw">move </span>|| { |
| <span class="kw">for </span>i <span class="kw">in </span><span class="number">1</span>..=<span class="number">5 </span>{ |
| tx.unbounded_send(<span class="prelude-val">Ok</span>(i)).unwrap(); |
| } |
| tx.unbounded_send(<span class="prelude-val">Err</span>(<span class="number">6</span>)).unwrap(); |
| }); |
| |
| <span class="kw">let </span>output: <span class="prelude-ty">Result</span><Vec<i32>, i32> = rx.try_collect().<span class="kw">await</span>; |
| <span class="macro">assert_eq!</span>(output, <span class="prelude-val">Err</span>(<span class="number">6</span>));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_chunks" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#634-636">source</a><h4 class="code-header">fn <a href="#method.try_chunks" class="fnname">try_chunks</a>(self, capacity: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="../../stream/struct.TryChunks.html" title="struct futures::stream::TryChunks">TryChunks</a><Self></h4></section></summary><div class="docblock"><p>An adaptor for chunking up successful items of the stream inside a vector.</p> |
| <p>This combinator will attempt to pull successful items from this stream and buffer |
| them into a local vector. At most <code>capacity</code> items will get buffered |
| before they’re yielded from the returned stream.</p> |
| <p>Note that the vectors returned from this iterator may not always have |
| <code>capacity</code> elements. If the underlying stream ended and only a partial |
| vector was created, it’ll be returned. Additionally if an error happens |
| from the underlying stream then the currently buffered items will be |
| 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> |
| <p>This function is similar to |
| <a href="../../stream/trait.StreamExt.html#method.chunks"><code>StreamExt::chunks</code></a> but exits |
| early if an error occurs.</p> |
| <h5 id="examples-11"><a href="#examples-11">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryChunksError, TryStreamExt}; |
| |
| <span class="kw">let </span>stream = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>::<i32, i32>(<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">Err</span>(<span class="number">4</span>), <span class="prelude-val">Ok</span>(<span class="number">5</span>), <span class="prelude-val">Ok</span>(<span class="number">6</span>)]); |
| <span class="kw">let </span><span class="kw-2">mut </span>stream = stream.try_chunks(<span class="number">2</span>); |
| |
| <span class="macro">assert_eq!</span>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>]))); |
| <span class="macro">assert_eq!</span>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Err</span>(TryChunksError(<span class="macro">vec!</span>[<span class="number">3</span>], <span class="number">4</span>))); |
| <span class="macro">assert_eq!</span>(stream.try_next().<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(<span class="macro">vec!</span>[<span class="number">5</span>, <span class="number">6</span>])));</code></pre></div> |
| <h5 id="panics"><a href="#panics">Panics</a></h5> |
| <p>This method will panic if <code>capacity</code> is zero.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_filter" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#673-677">source</a><h4 class="code-header">fn <a href="#method.try_filter" class="fnname">try_filter</a><Fut, F>(self, f: F) -> <a class="struct" href="../../stream/struct.TryFilter.html" title="struct futures::stream::TryFilter">TryFilter</a><Self, Fut, F><span class="where fmt-newline">where<br> Fut: <a class="trait" href="../../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>>,<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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,</span></h4></section></summary><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> |
| <h5 id="examples-12"><a href="#examples-12">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::future; |
| <span class="kw">use </span>futures::stream::{<span class="self">self</span>, StreamExt, TryStreamExt}; |
| |
| <span class="kw">let </span>stream = stream::iter(<span class="macro">vec!</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>evens = stream.try_filter(|x| { |
| future::ready(x % <span class="number">2 </span>== <span class="number">0</span>) |
| }); |
| |
| <span class="macro">assert_eq!</span>(evens.next().<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>(evens.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="string">"error"</span>)));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_filter_map" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#714-718">source</a><h4 class="code-header">fn <a href="#method.try_filter_map" class="fnname">try_filter_map</a><Fut, F, T>(self, f: F) -> <a class="struct" href="../../stream/struct.TryFilterMap.html" title="struct futures::stream::TryFilterMap">TryFilterMap</a><Self, Fut, F><span class="where fmt-newline">where<br> Fut: <a class="trait" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,<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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,</span></h4></section></summary><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> |
| <h5 id="examples-13"><a href="#examples-13">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{<span class="self">self</span>, StreamExt, TryStreamExt}; |
| <span class="kw">use </span>futures::pin_mut; |
| |
| <span class="kw">let </span>stream = stream::iter(<span class="macro">vec!</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>halves = stream.try_filter_map(|x| <span class="kw">async move </span>{ |
| <span class="kw">let </span>ret = <span class="kw">if </span>x % <span class="number">2 </span>== <span class="number">0 </span>{ <span class="prelude-val">Some</span>(x / <span class="number">2</span>) } <span class="kw">else </span>{ <span class="prelude-val">None </span>}; |
| <span class="prelude-val">Ok</span>(ret) |
| }); |
| |
| <span class="macro">pin_mut!</span>(halves); |
| <span class="macro">assert_eq!</span>(halves.next().<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>(halves.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="string">"error"</span>)));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_flatten_unordered" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#769-773">source</a><h4 class="code-header">fn <a href="#method.try_flatten_unordered" class="fnname">try_flatten_unordered</a>(<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>) -> <a class="struct" href="../../stream/struct.TryFlattenUnordered.html" title="struct futures::stream::TryFlattenUnordered">TryFlattenUnordered</a><Self><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><div class="docblock"><p>Flattens a stream of streams into just one continuous stream. Produced streams |
| will be polled concurrently and any errors will be passed through without looking at them. |
| If the underlying base stream returns an error, it will be <strong>immediately</strong> propagated.</p> |
| <p>The only argument is an optional limit on the number of concurrently |
| polled streams. If this limit is not <code>None</code>, no more than <code>limit</code> streams |
| will be polled at the same time. The <code>limit</code> argument is of type |
| <code>Into<Option<usize>></code>, and so can be provided as either <code>None</code>, |
| <code>Some(10)</code>, or just <code>10</code>. Note: a limit of zero is interpreted as |
| no limit at all, and will have the same result as passing in <code>None</code>.</p> |
| <h5 id="examples-14"><a href="#examples-14">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::mpsc; |
| <span class="kw">use </span>futures::stream::{StreamExt, TryStreamExt}; |
| <span class="kw">use </span>std::thread; |
| |
| <span class="kw">let </span>(tx1, rx1) = mpsc::unbounded(); |
| <span class="kw">let </span>(tx2, rx2) = mpsc::unbounded(); |
| <span class="kw">let </span>(tx3, rx3) = mpsc::unbounded(); |
| |
| thread::spawn(<span class="kw">move </span>|| { |
| tx1.unbounded_send(<span class="prelude-val">Ok</span>(<span class="number">1</span>)).unwrap(); |
| }); |
| thread::spawn(<span class="kw">move </span>|| { |
| tx2.unbounded_send(<span class="prelude-val">Ok</span>(<span class="number">2</span>)).unwrap(); |
| tx2.unbounded_send(<span class="prelude-val">Err</span>(<span class="number">3</span>)).unwrap(); |
| tx2.unbounded_send(<span class="prelude-val">Ok</span>(<span class="number">4</span>)).unwrap(); |
| }); |
| thread::spawn(<span class="kw">move </span>|| { |
| tx3.unbounded_send(<span class="prelude-val">Ok</span>(rx1)).unwrap(); |
| tx3.unbounded_send(<span class="prelude-val">Ok</span>(rx2)).unwrap(); |
| tx3.unbounded_send(<span class="prelude-val">Err</span>(<span class="number">5</span>)).unwrap(); |
| }); |
| |
| <span class="kw">let </span>stream = rx3.try_flatten_unordered(<span class="prelude-val">None</span>); |
| <span class="kw">let </span><span class="kw-2">mut </span>values: Vec<<span class="kw">_</span>> = stream.collect().<span class="kw">await</span>; |
| values.sort(); |
| |
| <span class="macro">assert_eq!</span>(values, <span class="macro">vec!</span>[<span class="prelude-val">Ok</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">4</span>), <span class="prelude-val">Err</span>(<span class="number">3</span>), <span class="prelude-val">Err</span>(<span class="number">5</span>)]);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_flatten" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#822-826">source</a><h4 class="code-header">fn <a href="#method.try_flatten" class="fnname">try_flatten</a>(self) -> <a class="struct" href="../../stream/struct.TryFlatten.html" title="struct futures::stream::TryFlatten">TryFlatten</a><Self><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<br> <Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a> as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><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> |
| <h5 id="examples-15"><a href="#examples-15">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::mpsc; |
| <span class="kw">use </span>futures::stream::{StreamExt, TryStreamExt}; |
| <span class="kw">use </span>std::thread; |
| |
| <span class="kw">let </span>(tx1, rx1) = mpsc::unbounded(); |
| <span class="kw">let </span>(tx2, rx2) = mpsc::unbounded(); |
| <span class="kw">let </span>(tx3, rx3) = mpsc::unbounded(); |
| |
| thread::spawn(<span class="kw">move </span>|| { |
| tx1.unbounded_send(<span class="prelude-val">Ok</span>(<span class="number">1</span>)).unwrap(); |
| }); |
| thread::spawn(<span class="kw">move </span>|| { |
| tx2.unbounded_send(<span class="prelude-val">Ok</span>(<span class="number">2</span>)).unwrap(); |
| tx2.unbounded_send(<span class="prelude-val">Err</span>(<span class="number">3</span>)).unwrap(); |
| tx2.unbounded_send(<span class="prelude-val">Ok</span>(<span class="number">4</span>)).unwrap(); |
| }); |
| thread::spawn(<span class="kw">move </span>|| { |
| tx3.unbounded_send(<span class="prelude-val">Ok</span>(rx1)).unwrap(); |
| tx3.unbounded_send(<span class="prelude-val">Ok</span>(rx2)).unwrap(); |
| tx3.unbounded_send(<span class="prelude-val">Err</span>(<span class="number">5</span>)).unwrap(); |
| }); |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>stream = rx3.try_flatten(); |
| <span class="macro">assert_eq!</span>(stream.next().<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>(stream.next().<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>(stream.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="number">3</span>))); |
| <span class="macro">assert_eq!</span>(stream.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">4</span>))); |
| <span class="macro">assert_eq!</span>(stream.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(<span class="number">5</span>))); |
| <span class="macro">assert_eq!</span>(stream.next().<span class="kw">await</span>, <span class="prelude-val">None</span>);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_fold" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#861-865">source</a><h4 class="code-header">fn <a href="#method.try_fold" class="fnname">try_fold</a><T, Fut, F>(self, init: T, f: F) -> <a class="struct" href="../../stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><Self, Fut, T, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><St, Fut, T, F></span><code class="content"><span class="where fmt-newline">impl<St, Fut, T, F> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryFold.html" title="struct futures::stream::TryFold">TryFold</a><St, Fut, T, F><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = T, Error = <St as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></span><span class="where fmt-newline"> type <a href="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = T, Error = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><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="../../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> |
| <h5 id="examples-16"><a href="#examples-16">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span>number_stream = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>::<i32, i32>(<span class="number">1</span>), <span class="prelude-val">Ok</span>(<span class="number">2</span>)]); |
| <span class="kw">let </span>sum = number_stream.try_fold(<span class="number">0</span>, |acc, x| <span class="kw">async move </span>{ <span class="prelude-val">Ok</span>(acc + x) }); |
| <span class="macro">assert_eq!</span>(sum.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="number">3</span>)); |
| |
| <span class="kw">let </span>number_stream_with_err = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>::<i32, i32>(<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>sum = number_stream_with_err.try_fold(<span class="number">0</span>, |acc, x| <span class="kw">async move </span>{ <span class="prelude-val">Ok</span>(acc + x) }); |
| <span class="macro">assert_eq!</span>(sum.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">2</span>));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_concat" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#904-907">source</a><h4 class="code-header">fn <a href="#method.try_concat" class="fnname">try_concat</a>(self) -> <a class="struct" href="../../stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="../../stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><St></span><code class="content"><span class="where fmt-newline">impl<St> <a class="trait" href="../../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="../../stream/struct.TryConcat.html" title="struct futures::stream::TryConcat">TryConcat</a><St><span class="where fmt-newline">where<br> St: <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>,<br> <St as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../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="associatedtype" 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>> + <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="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="../../future/trait.Future.html#associatedtype.Output" class="associatedtype">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="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>, <St as <a class="trait" href="../../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="../../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="associatedtype" href="../../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="associatedtype" 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>> + <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="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</span></h4></section></summary><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="../../stream/trait.StreamExt.html#method.concat"><code>concat</code></a>, but will |
| exit early if an error is encountered in the stream.</p> |
| <h5 id="examples-17"><a href="#examples-17">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::mpsc; |
| <span class="kw">use </span>futures::stream::TryStreamExt; |
| <span class="kw">use </span>std::thread; |
| |
| <span class="kw">let </span>(tx, rx) = mpsc::unbounded::<<span class="prelude-ty">Result</span><Vec<i32>, ()>>(); |
| |
| thread::spawn(<span class="kw">move </span>|| { |
| <span class="kw">for </span>i <span class="kw">in </span>(<span class="number">0</span>..<span class="number">3</span>).rev() { |
| <span class="kw">let </span>n = i * <span class="number">3</span>; |
| tx.unbounded_send(<span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[n + <span class="number">1</span>, n + <span class="number">2</span>, n + <span class="number">3</span>])).unwrap(); |
| } |
| }); |
| |
| <span class="kw">let </span>result = rx.try_concat().<span class="kw">await</span>; |
| |
| <span class="macro">assert_eq!</span>(result, <span class="prelude-val">Ok</span>(<span class="macro">vec!</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>]));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_buffer_unordered" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#971-974">source</a><h4 class="code-header">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="../../stream/struct.TryBufferUnordered.html" title="struct futures::stream::TryBufferUnordered">TryBufferUnordered</a><Self><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><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="../../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> |
| <h5 id="examples-18"><a href="#examples-18">Examples</a></h5> |
| <p>Results are returned in the order of completion:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::oneshot; |
| <span class="kw">use </span>futures::stream::{<span class="self">self</span>, StreamExt, TryStreamExt}; |
| |
| <span class="kw">let </span>(send_one, recv_one) = oneshot::channel(); |
| <span class="kw">let </span>(send_two, recv_two) = oneshot::channel(); |
| |
| <span class="kw">let </span>stream_of_futures = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(recv_one), <span class="prelude-val">Ok</span>(recv_two)]); |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>buffered = stream_of_futures.try_buffer_unordered(<span class="number">10</span>); |
| |
| send_two.send(<span class="number">2i32</span>)<span class="question-mark">?</span>; |
| <span class="macro">assert_eq!</span>(buffered.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">2i32</span>))); |
| |
| send_one.send(<span class="number">1i32</span>)<span class="question-mark">?</span>; |
| <span class="macro">assert_eq!</span>(buffered.next().<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>(buffered.next().<span class="kw">await</span>, <span class="prelude-val">None</span>);</code></pre></div> |
| <p>Errors from the underlying stream itself are propagated:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::mpsc; |
| <span class="kw">use </span>futures::stream::{StreamExt, TryStreamExt}; |
| |
| <span class="kw">let </span>(sink, stream_of_futures) = mpsc::unbounded(); |
| <span class="kw">let </span><span class="kw-2">mut </span>buffered = stream_of_futures.try_buffer_unordered(<span class="number">10</span>); |
| |
| sink.unbounded_send(<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>(buffered.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">7i32</span>))); |
| |
| sink.unbounded_send(<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>(buffered.next().<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>)));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_buffered" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#1047-1050">source</a><h4 class="code-header">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="../../stream/struct.TryBuffered.html" title="struct futures::stream::TryBuffered">TryBuffered</a><Self><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>: <a class="trait" href="../../future/trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Error" title="type futures::stream::TryStream::Error">Error</a>>,</span></h4></section></summary><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="../../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 same order as the underlying stream. 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> |
| <h5 id="examples-19"><a href="#examples-19">Examples</a></h5> |
| <p>Results are returned in the order of addition:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::oneshot; |
| <span class="kw">use </span>futures::future::lazy; |
| <span class="kw">use </span>futures::stream::{<span class="self">self</span>, StreamExt, TryStreamExt}; |
| |
| <span class="kw">let </span>(send_one, recv_one) = oneshot::channel(); |
| <span class="kw">let </span>(send_two, recv_two) = oneshot::channel(); |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>buffered = lazy(<span class="kw">move </span>|cx| { |
| <span class="kw">let </span>stream_of_futures = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(recv_one), <span class="prelude-val">Ok</span>(recv_two)]); |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>buffered = stream_of_futures.try_buffered(<span class="number">10</span>); |
| |
| <span class="macro">assert!</span>(buffered.try_poll_next_unpin(cx).is_pending()); |
| |
| send_two.send(<span class="number">2i32</span>)<span class="question-mark">?</span>; |
| <span class="macro">assert!</span>(buffered.try_poll_next_unpin(cx).is_pending()); |
| <span class="prelude-val">Ok</span>::<<span class="kw">_</span>, i32>(buffered) |
| }).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| send_one.send(<span class="number">1i32</span>)<span class="question-mark">?</span>; |
| <span class="macro">assert_eq!</span>(buffered.next().<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>(buffered.next().<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>(buffered.next().<span class="kw">await</span>, <span class="prelude-val">None</span>);</code></pre></div> |
| <p>Errors from the underlying stream itself are propagated:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::channel::mpsc; |
| <span class="kw">use </span>futures::stream::{StreamExt, TryStreamExt}; |
| |
| <span class="kw">let </span>(sink, stream_of_futures) = mpsc::unbounded(); |
| <span class="kw">let </span><span class="kw-2">mut </span>buffered = stream_of_futures.try_buffered(<span class="number">10</span>); |
| |
| sink.unbounded_send(<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>(buffered.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="number">7i32</span>))); |
| |
| sink.unbounded_send(<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>(buffered.next().<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>)));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_poll_next_unpin" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#1061-1066">source</a><h4 class="code-header">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="../../task/struct.Context.html" title="struct futures::task::Context">Context</a><'_><br>) -> <a class="enum" href="../../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="associatedtype" href="../../stream/trait.TryStream.html#associatedtype.Ok" title="type futures::stream::TryStream::Ok">Ok</a>, Self::<a class="associatedtype" href="../../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></h4></section></summary><div class="docblock"><p>A convenience method for calling <a href="../../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></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_async_read" class="method has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#1123-1126">source</a><h4 class="code-header">fn <a href="#method.into_async_read" class="fnname">into_async_read</a>(self) -> <a class="struct" href="../../stream/struct.IntoAsyncRead.html" title="struct futures::stream::IntoAsyncRead">IntoAsyncRead</a><Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="../../stream/trait.TryStreamExt.html" title="trait futures::stream::TryStreamExt">TryStreamExt</a><Error = <a class="struct" href="../../io/struct.Error.html" title="struct futures::io::Error">Error</a>>,<br> Self::<a class="associatedtype" href="../../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.u8.html">u8</a>]>,</span></h4></section></summary><div class="docblock"><p>Adapter that converts this stream into an <a href="../../io/trait.AsyncBufRead.html"><code>AsyncBufRead</code></a>.</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> |
| <h5 id="examples-20"><a href="#examples-20">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| <span class="kw">use </span>futures::io::AsyncReadExt; |
| |
| <span class="kw">let </span>stream = stream::iter([<span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]), <span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[<span class="number">4</span>, <span class="number">5</span>])]); |
| <span class="kw">let </span><span class="kw-2">mut </span>reader = stream.into_async_read(); |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>buf = Vec::new(); |
| reader.read_to_end(<span class="kw-2">&mut </span>buf).<span class="kw">await</span>.unwrap(); |
| <span class="macro">assert_eq!</span>(buf, [<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>]);</code></pre></div> |
| </div></details></div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"><section id="impl-TryStreamExt-for-S" class="impl has-srclink"><a class="srclink rightside" href="../../../src/futures_util/stream/try_stream/mod.rs.html#163">source</a><a href="#impl-TryStreamExt-for-S" class="anchor"></a><h3 class="code-header">impl<S> <a class="trait" href="../../stream/trait.TryStreamExt.html" title="trait futures::stream::TryStreamExt">TryStreamExt</a> for S<span class="where fmt-newline">where<br> S: <a class="trait" href="../../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></h3></section></div><script src="../../../implementors/futures_util/stream/try_stream/trait.TryStreamExt.js" async></script></section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="futures" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |