mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-27 04:19:33 +01:00
469 lines
94 KiB
HTML
469 lines
94 KiB
HTML
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Adapters specific to `Result`-returning streams"><title>TryStreamExt in futures_util::stream - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b0742ba02757f159.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="futures_util" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0 (90b35a623 2024-11-26)" data-channel="1.83.0" data-search-js="search-f0d225181b97f9a4.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-f070b9041d14864c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../futures_util/index.html">futures_<wbr>util</a><span class="version">0.3.31</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">TryStream<wbr>Ext</a></h2><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.and_then" title="and_then">and_then</a></li><li><a href="#method.err_into" title="err_into">err_into</a></li><li><a href="#method.inspect_err" title="inspect_err">inspect_err</a></li><li><a href="#method.inspect_ok" title="inspect_ok">inspect_ok</a></li><li><a href="#method.into_stream" title="into_stream">into_stream</a></li><li><a href="#method.map_err" title="map_err">map_err</a></li><li><a href="#method.map_ok" title="map_ok">map_ok</a></li><li><a href="#method.or_else" title="or_else">or_else</a></li><li><a href="#method.try_all" title="try_all">try_all</a></li><li><a href="#method.try_any" title="try_any">try_any</a></li><li><a href="#method.try_collect" title="try_collect">try_collect</a></li><li><a href="#method.try_concat" title="try_concat">try_concat</a></li><li><a href="#method.try_filter" title="try_filter">try_filter</a></li><li><a href="#method.try_filter_map" title="try_filter_map">try_filter_map</a></li><li><a href="#method.try_flatten" title="try_flatten">try_flatten</a></li><li><a href="#method.try_fold" title="try_fold">try_fold</a></li><li><a href="#method.try_for_each" title="try_for_each">try_for_each</a></li><li><a href="#method.try_next" title="try_next">try_next</a></li><li><a href="#method.try_poll_next_unpin" title="try_poll_next_unpin">try_poll_next_unpin</a></li><li><a href="#method.try_skip_while" title="try_skip_while">try_skip_while</a></li><li><a href="#method.try_take_while" title="try_take_while">try_take_while</a></li></ul><h3><a href="#object-safety">Object Safety</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In futures_<wbr>util::<wbr>stream</a></h2></div></div></nav><div class="sideb
|
|||
|
<details class="toggle type-contents-toggle"><summary class="hideme"><span>Show 21 methods</span></summary> // Provided methods
|
|||
|
fn <a href="#method.err_into" class="fn">err_into</a><E>(self) -> <a class="struct" href="struct.ErrInto.html" title="struct futures_util::stream::ErrInto">ErrInto</a><Self, E>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/1.83.0/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="fn">map_ok</a><T, F>(self, f: F) -> <a class="struct" href="struct.MapOk.html" title="struct futures_util::stream::MapOk">MapOk</a><Self, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> T</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.map_err" class="fn">map_err</a><E, F>(self, f: F) -> <a class="struct" href="struct.MapErr.html" title="struct futures_util::stream::MapErr">MapErr</a><Self, F>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>) -> E</span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.and_then" class="fn">and_then</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.AndThen.html" title="struct futures_util::stream::AndThen">AndThen</a><Self, Fut, F>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.or_else" class="fn">or_else</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.OrElse.html" title="struct futures_util::stream::OrElse">OrElse</a><Self, Fut, F>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.inspect_ok" class="fn">inspect_ok</a><F>(self, f: F) -> <a class="struct" href="struct.InspectOk.html" title="struct futures_util::stream::InspectOk">InspectOk</a><Self, F>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>),
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.inspect_err" class="fn">inspect_err</a><F>(self, f: F) -> <a class="struct" href="struct.InspectErr.html" title="struct futures_util::stream::InspectErr">InspectErr</a><Self, F>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>),
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.into_stream" class="fn">into_stream</a>(self) -> <a class="struct" href="struct.IntoStream.html" title="struct futures_util::stream::IntoStream">IntoStream</a><Self>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_next" class="fn">try_next</a>(&mut self) -> <a class="struct" href="struct.TryNext.html" title="struct futures_util::stream::TryNext">TryNext</a><'_, Self> <a href="#" class="tooltip" data-notable-ty="TryNext<'_, Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/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="fn">try_for_each</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryForEach.html" title="struct futures_util::stream::TryForEach">TryForEach</a><Self, Fut, F> <a href="#" class="tooltip" data-notable-ty="TryForEach<Self, Fut, F>">ⓘ</a>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.unit.html">()</a>, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_skip_while" class="fn">try_skip_while</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TrySkipWhile.html" title="struct futures_util::stream::TrySkipWhile">TrySkipWhile</a><Self, Fut, F>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_take_while" class="fn">try_take_while</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryTakeWhile.html" title="struct futures_util::stream::TryTakeWhile">TryTakeWhile</a><Self, Fut, F>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_collect" class="fn">try_collect</a><C: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>>>(self) -> <a class="struct" href="struct.TryCollect.html" title="struct futures_util::stream::TryCollect">TryCollect</a><Self, C> <a href="#" class="tooltip" data-notable-ty="TryCollect<Self, C>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_filter" class="fn">try_filter</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryFilter.html" title="struct futures_util::stream::TryFilter">TryFilter</a><Self, Fut, F>
|
|||
|
<span class="where">where Fut: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_filter_map" class="fn">try_filter_map</a><Fut, F, T>(self, f: F) -> <a class="struct" href="struct.TryFilterMap.html" title="struct futures_util::stream::TryFilterMap">TryFilterMap</a><Self, Fut, F>
|
|||
|
<span class="where">where Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = <a class="enum" href="https://doc.rust-lang.org/1.83.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_flatten" class="fn">try_flatten</a>(self) -> <a class="struct" href="struct.TryFlatten.html" title="struct futures_util::stream::TryFlatten">TryFlatten</a><Self>
|
|||
|
<span class="where">where Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>: <a class="trait" href="trait.TryStream.html" title="trait futures_util::stream::TryStream">TryStream</a>,
|
|||
|
<Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a> as <a class="trait" href="trait.TryStream.html" title="trait futures_util::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_fold" class="fn">try_fold</a><T, Fut, F>(self, init: T, f: F) -> <a class="struct" href="struct.TryFold.html" title="struct futures_util::stream::TryFold">TryFold</a><Self, Fut, T, F> <a href="#" class="tooltip" data-notable-ty="TryFold<Self, Fut, T, F>">ⓘ</a>
|
|||
|
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T, Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = T, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_concat" class="fn">try_concat</a>(self) -> <a class="struct" href="struct.TryConcat.html" title="struct futures_util::stream::TryConcat">TryConcat</a><Self> <a href="#" class="tooltip" data-notable-ty="TryConcat<Self>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<<Self as <a class="trait" href="trait.TryStream.html" title="trait futures_util::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a> as <a class="trait" href="https://doc.rust-lang.org/1.83.0/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/1.83.0/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/1.83.0/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/1.83.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_poll_next_unpin" class="fn">try_poll_next_unpin</a>(
|
|||
|
&mut self,
|
|||
|
cx: &mut <a class="struct" href="https://doc.rust-lang.org/1.83.0/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a><'_>,
|
|||
|
) -> <a class="enum" href="https://doc.rust-lang.org/1.83.0/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a><<a class="enum" href="https://doc.rust-lang.org/1.83.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="https://doc.rust-lang.org/1.83.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>, Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>>>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_all" class="fn">try_all</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryAll.html" title="struct futures_util::stream::TryAll">TryAll</a><Self, Fut, F> <a href="#" class="tooltip" data-notable-ty="TryAll<Self, Fut, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>></span> { ... }
|
|||
|
<span class="item-spacer"></span> fn <a href="#method.try_any" class="fn">try_any</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryAny.html" title="struct futures_util::stream::TryAny">TryAny</a><Self, Fut, F> <a href="#" class="tooltip" data-notable-ty="TryAny<Self, Fut, F>">ⓘ</a>
|
|||
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>></span> { ... }
|
|||
|
</details>}</code></pre><details class="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="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.err_into" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#198-204">source</a><h4 class="code-header">fn <a href="#method.err_into" class="fn">err_into</a><E>(self) -> <a class="struct" href="struct.ErrInto.html" title="struct futures_util::stream::ErrInto">ErrInto</a><Self, E><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><E>,</div></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 class="doc-anchor" href="#examples">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.map_ok" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#223-229">source</a><h4 class="code-header">fn <a href="#method.map_ok" class="fn">map_ok</a><T, F>(self, f: F) -> <a class="struct" href="struct.MapOk.html" title="struct futures_util::stream::MapOk">MapOk</a><Self, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> T,</div></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 class="doc-anchor" href="#examples-1">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.map_err" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#248-254">source</a><h4 class="code-header">fn <a href="#method.map_err" class="fn">map_err</a><E, F>(self, f: F) -> <a class="struct" href="struct.MapErr.html" title="struct futures_util::stream::MapErr">MapErr</a><Self, F><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>) -> E,</div></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 class="doc-anchor" href="#examples-2">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.and_then" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#294-301">source</a><h4 class="code-header">fn <a href="#method.and_then" class="fn">and_then</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.AndThen.html" title="struct futures_util::stream::AndThen">AndThen</a><Self, Fut, F><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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 class="doc-anchor" href="#examples-3">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.or_else" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#320-327">source</a><h4 class="code-header">fn <a href="#method.or_else" class="fn">or_else</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.OrElse.html" title="struct futures_util::stream::OrElse">OrElse</a><Self, Fut, F><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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" title="trait futures_util::future::TryFuture"><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="toggle method-toggle" open><summary><section id="method.inspect_ok" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#335-341">source</a><h4 class="code-header">fn <a href="#method.inspect_ok" class="fn">inspect_ok</a><F>(self, f: F) -> <a class="struct" href="struct.InspectOk.html" title="struct futures_util::stream::InspectOk">InspectOk</a><Self, F><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>),
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="toggle method-toggle" open><summary><section id="method.inspect_err" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#348-354">source</a><h4 class="code-header">fn <a href="#method.inspect_err" class="fn">inspect_err</a><F>(self, f: F) -> <a class="struct" href="struct.InspectErr.html" title="struct futures_util::stream::InspectErr">InspectErr</a><Self, F><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>),
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="toggle method-toggle" open><summary><section id="method.into_stream" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#377-382">source</a><h4 class="code-header">fn <a href="#method.into_stream" class="fn">into_stream</a>(self) -> <a class="struct" href="struct.IntoStream.html" title="struct futures_util::stream::IntoStream">IntoStream</a><Self><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Wraps a <a href="trait.TryStream.html" title="trait futures_util::stream::TryStream"><code>TryStream</code></a> into a type that implements
|
|||
|
<a href="trait.Stream.html" title="trait futures_util::stream::Stream"><code>Stream</code></a></p>
|
|||
|
<p><a href="trait.TryStream.html" title="trait futures_util::stream::TryStream"><code>TryStream</code></a>s currently do not implement the
|
|||
|
<a href="trait.Stream.html" title="trait futures_util::stream::Stream"><code>Stream</code></a> trait because of limitations
|
|||
|
of the compiler.</p>
|
|||
|
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_next" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#404-409">source</a><h4 class="code-header">fn <a href="#method.try_next" class="fn">try_next</a>(&mut self) -> <a class="struct" href="struct.TryNext.html" title="struct futures_util::stream::TryNext">TryNext</a><'_, Self> <a href="#" class="tooltip" data-notable-ty="TryNext<'_, Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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 class="doc-anchor" href="#examples-5">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_for_each" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#444-451">source</a><h4 class="code-header">fn <a href="#method.try_for_each" class="fn">try_for_each</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryForEach.html" title="struct futures_util::stream::TryForEach">TryForEach</a><Self, Fut, F> <a href="#" class="tooltip" data-notable-ty="TryForEach<Self, Fut, F>">ⓘ</a><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.unit.html">()</a>, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html" title="trait core::future::future::Future"><code>Future</code></a> where the
|
|||
|
<a href="https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html#associatedtype.Output" title="associated type core::future::future::Future::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 class="doc-anchor" href="#examples-6">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_skip_while" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#474-481">source</a><h4 class="code-header">fn <a href="#method.try_skip_while" class="fn">try_skip_while</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TrySkipWhile.html" title="struct futures_util::stream::TrySkipWhile">TrySkipWhile</a><Self, Fut, F><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="trait.StreamExt.html#method.skip_while" title="method futures_util::stream::StreamExt::skip_while"><code>StreamExt::skip_while</code></a> but exits
|
|||
|
early if an error occurs.</p>
|
|||
|
<h5 id="examples-7"><a class="doc-anchor" href="#examples-7">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_take_while" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#504-511">source</a><h4 class="code-header">fn <a href="#method.try_take_while" class="fn">try_take_while</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryTakeWhile.html" title="struct futures_util::stream::TryTakeWhile">TryTakeWhile</a><Self, Fut, F><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="trait.StreamExt.html#method.take_while" title="method futures_util::stream::StreamExt::take_while"><code>StreamExt::take_while</code></a> but exits
|
|||
|
early if an error occurs.</p>
|
|||
|
<h5 id="examples-8"><a class="doc-anchor" href="#examples-8">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_collect" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#603-608">source</a><h4 class="code-header">fn <a href="#method.try_collect" class="fn">try_collect</a><C: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>>>(self) -> <a class="struct" href="struct.TryCollect.html" title="struct futures_util::stream::TryCollect">TryCollect</a><Self, C> <a href="#" class="tooltip" data-notable-ty="TryCollect<Self, C>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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-9"><a class="doc-anchor" href="#examples-9">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_filter" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#736-743">source</a><h4 class="code-header">fn <a href="#method.try_filter" class="fn">try_filter</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryFilter.html" title="struct futures_util::stream::TryFilter">TryFilter</a><Self, Fut, F><div class="where">where
|
|||
|
Fut: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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-10"><a class="doc-anchor" href="#examples-10">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_filter_map" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#777-784">source</a><h4 class="code-header">fn <a href="#method.try_filter_map" class="fn">try_filter_map</a><Fut, F, T>(self, f: F) -> <a class="struct" href="struct.TryFilterMap.html" title="struct futures_util::stream::TryFilterMap">TryFilterMap</a><Self, Fut, F><div class="where">where
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = <a class="enum" href="https://doc.rust-lang.org/1.83.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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/1.83.0/core/option/enum.Option.html#variant.Some" title="variant core::option::Option::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/1.83.0/core/option/enum.Option.html#variant.None" title="variant core::option::Option::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-11"><a class="doc-anchor" href="#examples-11">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_flatten" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#885-894">source</a><h4 class="code-header">fn <a href="#method.try_flatten" class="fn">try_flatten</a>(self) -> <a class="struct" href="struct.TryFlatten.html" title="struct futures_util::stream::TryFlatten">TryFlatten</a><Self><div class="where">where
|
|||
|
Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>: <a class="trait" href="trait.TryStream.html" title="trait futures_util::stream::TryStream">TryStream</a>,
|
|||
|
<Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a> as <a class="trait" href="trait.TryStream.html" title="trait futures_util::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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-12"><a class="doc-anchor" href="#examples-12">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_fold" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#924-931">source</a><h4 class="code-header">fn <a href="#method.try_fold" class="fn">try_fold</a><T, Fut, F>(self, init: T, f: F) -> <a class="struct" href="struct.TryFold.html" title="struct futures_util::stream::TryFold">TryFold</a><Self, Fut, T, F> <a href="#" class="tooltip" data-notable-ty="TryFold<Self, Fut, T, F>">ⓘ</a><div class="where">where
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(T, Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="../future/trait.TryFuture.html" title="trait futures_util::future::TryFuture">TryFuture</a><Ok = T, Error = Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>,
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></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="trait.StreamExt.html#method.fold" title="method futures_util::stream::StreamExt::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-13"><a class="doc-anchor" href="#examples-13">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_concat" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#967-973">source</a><h4 class="code-header">fn <a href="#method.try_concat" class="fn">try_concat</a>(self) -> <a class="struct" href="struct.TryConcat.html" title="struct futures_util::stream::TryConcat">TryConcat</a><Self> <a href="#" class="tooltip" data-notable-ty="TryConcat<Self>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><<<Self as <a class="trait" href="trait.TryStream.html" title="trait futures_util::stream::TryStream">TryStream</a>>::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a> as <a class="trait" href="https://doc.rust-lang.org/1.83.0/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/1.83.0/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/1.83.0/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/1.83.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</div></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="std::iter::Extend"><code>Extend</code></a> trait.</p>
|
|||
|
<p>This method is similar to <a href="trait.StreamExt.html#method.concat" title="method futures_util::stream::StreamExt::concat"><code>concat</code></a>, but will
|
|||
|
exit early if an error is encountered in the stream.</p>
|
|||
|
<h5 id="examples-14"><a class="doc-anchor" href="#examples-14">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.try_poll_next_unpin" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#1124-1132">source</a><h4 class="code-header">fn <a href="#method.try_poll_next_unpin" class="fn">try_poll_next_unpin</a>(
|
|||
|
&mut self,
|
|||
|
cx: &mut <a class="struct" href="https://doc.rust-lang.org/1.83.0/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a><'_>,
|
|||
|
) -> <a class="enum" href="https://doc.rust-lang.org/1.83.0/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a><<a class="enum" href="https://doc.rust-lang.org/1.83.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="https://doc.rust-lang.org/1.83.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>, Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Error" title="type futures_util::stream::TryStream::Error">Error</a>>>><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></h4></section></summary><div class="docblock"><p>A convenience method for calling <a href="trait.TryStream.html#tymethod.try_poll_next" title="method futures_util::stream::TryStream::try_poll_next"><code>TryStream::try_poll_next</code></a> on <a href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin"><code>Unpin</code></a>
|
|||
|
stream types.</p>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_all" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#1214-1221">source</a><h4 class="code-header">fn <a href="#method.try_all" class="fn">try_all</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryAll.html" title="struct futures_util::stream::TryAll">TryAll</a><Self, Fut, F> <a href="#" class="tooltip" data-notable-ty="TryAll<Self, Fut, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>>,</div></h4></section></summary><div class="docblock"><p>Attempt to execute a predicate over an asynchronous stream and evaluate if all items
|
|||
|
satisfy the predicate. Exits early if an <code>Err</code> is encountered or if an <code>Ok</code> item is found
|
|||
|
that does not satisfy the predicate.</p>
|
|||
|
<h5 id="examples-15"><a class="doc-anchor" href="#examples-15">§</a>Examples</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>std::convert::Infallible;
|
|||
|
|
|||
|
<span class="kw">let </span>number_stream = stream::iter(<span class="number">1</span>..<span class="number">10</span>).map(<span class="prelude-val">Ok</span>::<<span class="kw">_</span>, Infallible>);
|
|||
|
<span class="kw">let </span>positive = number_stream.try_all(|i| <span class="kw">async move </span>{ i > <span class="number">0 </span>});
|
|||
|
<span class="macro">assert_eq!</span>(positive.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="bool-val">true</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>stream_with_errors = stream::iter([<span class="prelude-val">Ok</span>(<span class="number">1</span>), <span class="prelude-val">Err</span>(<span class="string">"err"</span>), <span class="prelude-val">Ok</span>(<span class="number">3</span>)]);
|
|||
|
<span class="kw">let </span>positive = stream_with_errors.try_all(|i| <span class="kw">async move </span>{ i > <span class="number">0 </span>});
|
|||
|
<span class="macro">assert_eq!</span>(positive.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="string">"err"</span>));</code></pre></div>
|
|||
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_any" class="method"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#1243-1250">source</a><h4 class="code-header">fn <a href="#method.try_any" class="fn">try_any</a><Fut, F>(self, f: F) -> <a class="struct" href="struct.TryAny.html" title="struct futures_util::stream::TryAny">TryAny</a><Self, Fut, F> <a href="#" class="tooltip" data-notable-ty="TryAny<Self, Fut, F>">ⓘ</a><div class="where">where
|
|||
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
|||
|
F: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(Self::<a class="associatedtype" href="trait.TryStream.html#associatedtype.Ok" title="type futures_util::stream::TryStream::Ok">Ok</a>) -> Fut,
|
|||
|
Fut: <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="primitive" href="https://doc.rust-lang.org/1.83.0/core/primitive.bool.html">bool</a>>,</div></h4></section></summary><div class="docblock"><p>Attempt to execute a predicate over an asynchronous stream and evaluate if any items
|
|||
|
satisfy the predicate. Exits early if an <code>Err</code> is encountered or if an <code>Ok</code> item is found
|
|||
|
that satisfies the predicate.</p>
|
|||
|
<h5 id="examples-16"><a class="doc-anchor" href="#examples-16">§</a>Examples</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>std::convert::Infallible;
|
|||
|
|
|||
|
<span class="kw">let </span>number_stream = stream::iter(<span class="number">0</span>..<span class="number">10</span>).map(<span class="prelude-val">Ok</span>::<<span class="kw">_</span>, Infallible>);
|
|||
|
<span class="kw">let </span>contain_three = number_stream.try_any(|i| <span class="kw">async move </span>{ i == <span class="number">3 </span>});
|
|||
|
<span class="macro">assert_eq!</span>(contain_three.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="bool-val">true</span>));
|
|||
|
|
|||
|
<span class="kw">let </span>stream_with_errors = stream::iter([<span class="prelude-val">Ok</span>(<span class="number">1</span>), <span class="prelude-val">Err</span>(<span class="string">"err"</span>), <span class="prelude-val">Ok</span>(<span class="number">3</span>)]);
|
|||
|
<span class="kw">let </span>contain_three = stream_with_errors.try_any(|i| <span class="kw">async move </span>{ i == <span class="number">3 </span>});
|
|||
|
<span class="macro">assert_eq!</span>(contain_three.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="string">"err"</span>));</code></pre></div>
|
|||
|
</div></details></div><h2 id="object-safety" class="section-header">Object Safety<a href="#object-safety" class="anchor">§</a></h2><div class="object-safety-info">This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.83.0/reference/items/traits.html#object-safety">object safe</a>.</div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-TryStreamExt-for-S" class="impl"><a class="src rightside" href="../../src/futures_util/stream/try_stream/mod.rs.html#177">source</a><a href="#impl-TryStreamExt-for-S" class="anchor">§</a><h3 class="code-header">impl<S: ?<a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.TryStream.html" title="trait futures_util::stream::TryStream">TryStream</a>> <a class="trait" href="trait.TryStreamExt.html" title="trait futures_util::stream::TryStreamExt">TryStreamExt</a> for S</h3></section></div><script src="../../trait.impl/futures_util/stream/try_stream/trait.TryStreamExt.js" async></script><script type="text/json" id="notable-traits-data">{"TryAll<Self, Fut, F>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.TryAll.html\" title=\"struct futures_util::stream::TryAll\">TryAll</a><St, Fut, F></code></h3><pre><code><div class=\"where\">impl<St, Fut, F> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.TryAll.html\" title=\"struct futures_util::stream::TryAll\">TryAll</a><St, Fut, F><div class=\"where\">where\n St: <a class=\"trait\" href=\"trait.TryStream.html\" title=\"trait futures_util::stream::TryStream\">TryStream</a>,\n F: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html\" title=\"trait core::ops::function::FnMut\">FnMut</a>(St::<a class=\"associatedtype\" href=\"trait.TryStream.html#associatedtype.Ok\" title=\"type futures_util::stream::TryStream::Ok\">Ok</a>) -> Fut,\n Fut: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a><Output = <a class=\"primitive\" href=\"https://doc.rust-lang.org/1.83.0/core/primitive.bool.html\">bool</a>>,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = <a class=\"enum\" href=\"https://doc.rust-lang.org/1.83.0/core/result/enum.Result.html\" title=\"enum core::result::Result\">Result</a><<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.83.0/core/primitive.bool.html\">bool</a>, St::<a class=\"associatedtype\" href=\"trait.TryStream.html#associatedtype.Error\" title=\"type futures_util::stream::TryStream::Error\">Error</a>>;</div>","TryAny<Self, Fut, F>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.TryAny.html\" title=\"struct futures_util::stream::TryAny\">TryAny</a><St, Fut, F></code></h3><pre><code><div class=\"where\">impl<St, Fut, F> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.83.0/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.TryAny.html\" title=\"struct futures_util::stream::TryAny\">TryAny</a><St, Fut, F><div class=\"where\">where\n St: <a class=\"trait\" href=\"trait.TryStream.html\" title=\"trait futures_util::stream::TryStream\">TryStream</a>,\n F: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.83.0/core/ops/function/trait.FnMut.html\" title=\"trait core::ops::function::FnMut\">FnMut</a>(St::<a class=\"associatedtype\" href=\"trait.TryStream.html#associatedtype.Ok\" title=\"type futures_util::stream::TryStream::Ok\">Ok</a>) -> Fut,\n Fut: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.83.0/core/fu
|