| <!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 futures"><meta name="keywords" content="rust, rustlang, rust-lang, TryFutureExt"><title>TryFutureExt in futures::future - 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="#">TryFutureExt</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.flatten_sink">flatten_sink</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_future">into_future</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.map_ok_or_else">map_ok_or_else</a></li><li><a href="#method.ok_into">ok_into</a></li><li><a href="#method.or_else">or_else</a></li><li><a href="#method.try_flatten">try_flatten</a></li><li><a href="#method.try_flatten_stream">try_flatten_stream</a></li><li><a href="#method.try_poll_unpin">try_poll_unpin</a></li><li><a href="#method.unwrap_or_else">unwrap_or_else</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In futures::future</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">future</a>::<wbr><a class="trait" href="#">TryFutureExt</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/future/try_future/mod.rs.html#137">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 TryFutureExt: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a> { |
| <details class="rustdoc-toggle type-contents-toggle"><summary class="hideme"><span>Show 15 methods</span></summary> fn <a href="#method.flatten_sink" class="fnname">flatten_sink</a><Item>(self) -> <a class="struct" href="struct.FlattenSink.html" title="struct futures::future::FlattenSink">FlattenSink</a><Self, Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>><br> <span class="where">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>: <a class="trait" href="../sink/trait.Sink.html" title="trait futures::sink::Sink">Sink</a><Item, Error = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>></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="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Self, 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="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, MapOkFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, MapOkFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>) -> T</span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.map_ok_or_else" class="fnname">map_ok_or_else</a><T, E, F>(self, e: E, f: F) -> <a class="struct" href="struct.MapOkOrElse.html" title="struct futures::future::MapOkOrElse">MapOkOrElse</a><Self, F, E><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="struct.MapOkOrElse.html" title="struct futures::future::MapOkOrElse">MapOkOrElse</a><Fut, F, G></span><code class="content"><span class="where fmt-newline">impl<Fut, F, G> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.MapOkOrElse.html" title="struct futures::future::MapOkOrElse">MapOkOrElse</a><Fut, F, G><span class="where fmt-newline">where<br> <a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, ChainFn<MapOkFn<F>, ChainFn<MapErrFn<G>, MergeResultFn>>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, ChainFn<MapOkFn<F>, ChainFn<MapErrFn<G>, MergeResultFn>>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>) -> T,<br> E: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</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="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Self, 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="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, MapErrFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, MapErrFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>) -> E</span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.err_into" class="fnname">err_into</a><E>(self) -> <a class="struct" href="struct.ErrInto.html" title="struct futures::future::ErrInto">ErrInto</a><Self, E><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="struct.ErrInto.html" title="struct futures::future::ErrInto">ErrInto</a><Fut, E></span><code class="content"><span class="where fmt-newline">impl<Fut, E> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.ErrInto.html" title="struct futures::future::ErrInto">ErrInto</a><Fut, E><span class="where fmt-newline">where<br> <a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut, IntoFn<E>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut, IntoFn<E>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>: Into<E></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.ok_into" class="fnname">ok_into</a><U>(self) -> <a class="struct" href="struct.OkInto.html" title="struct futures::future::OkInto">OkInto</a><Self, U><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="struct.OkInto.html" title="struct futures::future::OkInto">OkInto</a><Fut, E></span><code class="content"><span class="where fmt-newline">impl<Fut, E> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.OkInto.html" title="struct futures::future::OkInto">OkInto</a><Fut, E><span class="where fmt-newline">where<br> <a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut, IntoFn<E>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut, IntoFn<E>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>: Into<U></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="struct.AndThen.html" title="struct futures::future::AndThen">AndThen</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="struct.AndThen.html" title="struct futures::future::AndThen">AndThen</a><Fut1, Fut2, F></span><code class="content"><span class="where fmt-newline">impl<Fut1, Fut2, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.AndThen.html" title="struct futures::future::AndThen">AndThen</a><Fut1, Fut2, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><<a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut1, F>, Fut2>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><<a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut1, F>, Fut2> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::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="struct.OrElse.html" title="struct futures::future::OrElse">OrElse</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="struct.OrElse.html" title="struct futures::future::OrElse">OrElse</a><Fut1, Fut2, F></span><code class="content"><span class="where fmt-newline">impl<Fut1, Fut2, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.OrElse.html" title="struct futures::future::OrElse">OrElse</a><Fut1, Fut2, F><span class="where fmt-newline">where<br> TryFlattenErr<<a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut1, F>, Fut2>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <TryFlattenErr<<a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut1, F>, Fut2> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>) -> Fut,<br> Fut: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::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="struct.InspectOk.html" title="struct futures::future::InspectOk">InspectOk</a><Self, 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="struct.InspectOk.html" title="struct futures::future::InspectOk">InspectOk</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.InspectOk.html" title="struct futures::future::InspectOk">InspectOk</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Inspect.html" title="struct futures::future::Inspect">Inspect</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, InspectOkFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Inspect.html" title="struct futures::future::Inspect">Inspect</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, InspectOkFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> F: FnOnce(&Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::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="struct.InspectErr.html" title="struct futures::future::InspectErr">InspectErr</a><Self, 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="struct.InspectErr.html" title="struct futures::future::InspectErr">InspectErr</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.InspectErr.html" title="struct futures::future::InspectErr">InspectErr</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Inspect.html" title="struct futures::future::Inspect">Inspect</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, InspectErrFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Inspect.html" title="struct futures::future::Inspect">Inspect</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, InspectErrFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> F: FnOnce(&Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::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="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><Self, Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>><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="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><Fut1, Fut2></span><code class="content"><span class="where fmt-newline">impl<Fut1, Fut2> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><Fut1, Fut2><span class="where fmt-newline">where<br> TryFlatten<Fut1, Fut2>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <TryFlatten<Fut1, Fut2> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_flatten_stream" class="fnname">try_flatten_stream</a>(self) -> <a class="struct" href="struct.TryFlattenStream.html" title="struct futures::future::TryFlattenStream">TryFlattenStream</a><Self><br> <span class="where">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>: <a class="trait" href="../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a><Error = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.unwrap_or_else" class="fnname">unwrap_or_else</a><F>(self, f: F) -> <a class="struct" href="struct.UnwrapOrElse.html" title="struct futures::future::UnwrapOrElse">UnwrapOrElse</a><Self, 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="struct.UnwrapOrElse.html" title="struct futures::future::UnwrapOrElse">UnwrapOrElse</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.UnwrapOrElse.html" title="struct futures::future::UnwrapOrElse">UnwrapOrElse</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, UnwrapOrElseFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, UnwrapOrElseFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><br> <span class="where">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>) -> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.into_future" class="fnname">into_future</a>(self) -> <a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</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="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut></span><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut><span class="where fmt-newline">where<br> Fut: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = Result<<Fut as <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>>::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>, <Fut as <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>>::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>>;</span></code></span></span></span></span> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.try_poll_unpin" class="fnname">try_poll_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><Result<Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>, Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>>><br> <span class="where">where<br> Self: Unpin</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 futures</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.flatten_sink" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/future/try_future/mod.rs.html#171-174">source</a><h4 class="code-header">fn <a href="#method.flatten_sink" class="fnname">flatten_sink</a><Item>(self) -> <a class="struct" href="struct.FlattenSink.html" title="struct futures::future::FlattenSink">FlattenSink</a><Self, Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>: <a class="trait" href="../sink/trait.Sink.html" title="trait futures::sink::Sink">Sink</a><Item, Error = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>>,</span></h4></section></summary><div class="docblock"><p>Flattens the execution of this future when the successful result of this |
| future is a <a href="../sink/trait.Sink.html" title="Sink"><code>Sink</code></a>.</p> |
| <p>This can be useful when sink initialization is deferred, and it is |
| convenient to work with that sink as if the sink was available at the |
| call site.</p> |
| <p>Note that this function consumes this future and returns a wrapped |
| version of it.</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::future::{Future, TryFutureExt}; |
| <span class="kw">use </span>futures::sink::Sink; |
| |
| <span class="kw">fn </span>make_sink_async() -> <span class="kw">impl </span>Future<Output = <span class="prelude-ty">Result</span>< |
| <span class="kw">impl </span>Sink<T, Error = E>, |
| E, |
| >> { <span class="comment">// ... } |
| </span><span class="kw">fn </span>take_sink(sink: <span class="kw">impl </span>Sink<T, Error = E>) { <span class="comment">/* ... */ </span>} |
| |
| <span class="kw">let </span>fut = make_sink_async(); |
| take_sink(fut.flatten_sink())</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/future/try_future/mod.rs.html#217-220">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="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Self, 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="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, MapOkFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, MapOkFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>) -> T,</span></h4></section></summary><div class="docblock"><p>Maps this future’s success value to a different value.</p> |
| <p>This method can be used to change the <a href="trait.TryFuture.html#associatedtype.Ok"><code>Ok</code></a> type of the |
| future into a different type. It is similar to the [<code>Result::map</code>] |
| method. You can use this method to chain along a computation once the |
| future has been resolved.</p> |
| <p>The provided closure <code>f</code> will only be called if this future is resolved |
| to an [<code>Ok</code>]. If it resolves to an [<code>Err</code>], panics, or is dropped, then |
| the provided closure will never be invoked.</p> |
| <p>Note that this method consumes the future it is called on and returns a |
| wrapped version of it.</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::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Ok</span>::<i32, i32>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future = future.map_ok(|x| x + <span class="number">3</span>); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="number">4</span>));</code></pre></div> |
| <p>Calling <a href="trait.TryFutureExt.html#method.map_ok"><code>map_ok</code></a> on an errored future has no |
| effect:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Err</span>::<i32, i32>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future = future.map_ok(|x| x + <span class="number">3</span>); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">1</span>));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.map_ok_or_else" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/future/try_future/mod.rs.html#257-261">source</a><h4 class="code-header">fn <a href="#method.map_ok_or_else" class="fnname">map_ok_or_else</a><T, E, F>(self, e: E, f: F) -> <a class="struct" href="struct.MapOkOrElse.html" title="struct futures::future::MapOkOrElse">MapOkOrElse</a><Self, F, E><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="struct.MapOkOrElse.html" title="struct futures::future::MapOkOrElse">MapOkOrElse</a><Fut, F, G></span><code class="content"><span class="where fmt-newline">impl<Fut, F, G> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.MapOkOrElse.html" title="struct futures::future::MapOkOrElse">MapOkOrElse</a><Fut, F, G><span class="where fmt-newline">where<br> <a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, ChainFn<MapOkFn<F>, ChainFn<MapErrFn<G>, MergeResultFn>>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, ChainFn<MapOkFn<F>, ChainFn<MapErrFn<G>, MergeResultFn>>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>) -> T,<br> E: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>) -> T,</span></h4></section></summary><div class="docblock"><p>Maps this future’s success value to a different value, and permits for error handling resulting in the same type.</p> |
| <p>This method can be used to coalesce your <a href="trait.TryFuture.html#associatedtype.Ok"><code>Ok</code></a> type and <a href="trait.TryFuture.html#associatedtype.Error"><code>Error</code></a> into another type, |
| where that type is the same for both outcomes.</p> |
| <p>The provided closure <code>f</code> will only be called if this future is resolved |
| to an [<code>Ok</code>]. If it resolves to an [<code>Err</code>], panics, or is dropped, then |
| the provided closure will never be invoked.</p> |
| <p>The provided closure <code>e</code> will only be called if this future is resolved |
| to an [<code>Err</code>]. If it resolves to an [<code>Ok</code>], panics, or is dropped, then |
| the provided closure will never be invoked.</p> |
| <p>Note that this method consumes the future it is called on and returns a |
| wrapped version of it.</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::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Ok</span>::<i32, i32>(<span class="number">5</span>) }; |
| <span class="kw">let </span>future = future.map_ok_or_else(|x| x * <span class="number">2</span>, |x| x + <span class="number">3</span>); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="number">8</span>); |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Err</span>::<i32, i32>(<span class="number">5</span>) }; |
| <span class="kw">let </span>future = future.map_ok_or_else(|x| x * <span class="number">2</span>, |x| x + <span class="number">3</span>); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="number">10</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/future/try_future/mod.rs.html#308-311">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="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Self, 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="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, MapErrFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, MapErrFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>) -> E,</span></h4></section></summary><div class="docblock"><p>Maps this future’s error value to a different value.</p> |
| <p>This method can be used to change the <a href="trait.TryFuture.html#associatedtype.Error"><code>Error</code></a> type |
| of the future into a different type. It is similar to the |
| [<code>Result::map_err</code>] method. You can use this method for example to |
| ensure that futures have the same <a href="trait.TryFuture.html#associatedtype.Error"><code>Error</code></a> type when |
| using <a href="../macro.select.html"><code>select!</code></a> or <a href="../macro.join.html"><code>join!</code></a>.</p> |
| <p>The provided closure <code>f</code> will only be called if this future is resolved |
| to an [<code>Err</code>]. If it resolves to an [<code>Ok</code>], panics, or is dropped, then |
| the provided closure will never be invoked.</p> |
| <p>Note that this method consumes the future it is called on and returns a |
| wrapped version of it.</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::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Err</span>::<i32, i32>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future = future.map_err(|x| x + <span class="number">3</span>); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">4</span>));</code></pre></div> |
| <p>Calling <a href="trait.TryFutureExt.html#method.map_err"><code>map_err</code></a> on a successful future has |
| no effect:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Ok</span>::<i32, i32>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future = future.map_err(|x| x + <span class="number">3</span>); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="number">1</span>));</code></pre></div> |
| </div></details><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/future/try_future/mod.rs.html#341-344">source</a><h4 class="code-header">fn <a href="#method.err_into" class="fnname">err_into</a><E>(self) -> <a class="struct" href="struct.ErrInto.html" title="struct futures::future::ErrInto">ErrInto</a><Self, E><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="struct.ErrInto.html" title="struct futures::future::ErrInto">ErrInto</a><Fut, E></span><code class="content"><span class="where fmt-newline">impl<Fut, E> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.ErrInto.html" title="struct futures::future::ErrInto">ErrInto</a><Fut, E><span class="where fmt-newline">where<br> <a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut, IntoFn<E>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut, IntoFn<E>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>: Into<E>,</span></h4></section></summary><div class="docblock"><p>Maps this future’s <a href="trait.TryFuture.html#associatedtype.Error"><code>Error</code></a> to a new error type |
| using the <a href="std::convert::Into"><code>Into</code></a> trait.</p> |
| <p>This method does for futures what the <code>?</code>-operator does for |
| [<code>Result</code>]: It lets the compiler infer the type of the resulting |
| error. Just as <a href="trait.TryFutureExt.html#method.map_err"><code>map_err</code></a>, this is useful for |
| example to ensure that futures have the same <a href="trait.TryFuture.html#associatedtype.Error"><code>Error</code></a> |
| type when using <a href="../macro.select.html"><code>select!</code></a> or <a href="../macro.join.html"><code>join!</code></a>.</p> |
| <p>Note that this method consumes the future it is called on and returns a |
| wrapped version of it.</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::future::TryFutureExt; |
| |
| <span class="kw">let </span>future_err_u8 = <span class="kw">async </span>{ <span class="prelude-val">Err</span>::<(), u8>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future_err_i32 = future_err_u8.err_into::<i32>();</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ok_into" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/future/try_future/mod.rs.html#351-354">source</a><h4 class="code-header">fn <a href="#method.ok_into" class="fnname">ok_into</a><U>(self) -> <a class="struct" href="struct.OkInto.html" title="struct futures::future::OkInto">OkInto</a><Self, U><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="struct.OkInto.html" title="struct futures::future::OkInto">OkInto</a><Fut, E></span><code class="content"><span class="where fmt-newline">impl<Fut, E> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.OkInto.html" title="struct futures::future::OkInto">OkInto</a><Fut, E><span class="where fmt-newline">where<br> <a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut, IntoFn<E>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut, IntoFn<E>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>: Into<U>,</span></h4></section></summary><div class="docblock"><p>Maps this future’s <a href="trait.TryFuture.html#associatedtype.Ok"><code>Ok</code></a> to a new type |
| using the <a href="std::convert::Into"><code>Into</code></a> trait.</p> |
| </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/future/try_future/mod.rs.html#395-399">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="struct.AndThen.html" title="struct futures::future::AndThen">AndThen</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="struct.AndThen.html" title="struct futures::future::AndThen">AndThen</a><Fut1, Fut2, F></span><code class="content"><span class="where fmt-newline">impl<Fut1, Fut2, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.AndThen.html" title="struct futures::future::AndThen">AndThen</a><Fut1, Fut2, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><<a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut1, F>, Fut2>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><<a class="struct" href="struct.MapOk.html" title="struct futures::future::MapOk">MapOk</a><Fut1, F>, Fut2> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>) -> Fut,<br> Fut: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>>,</span></h4></section></summary><div class="docblock"><p>Executes another future after this one resolves successfully. The |
| success value is passed to a closure to create this subsequent future.</p> |
| <p>The provided closure <code>f</code> will only be called if this future is resolved |
| to an [<code>Ok</code>]. If this future resolves to an [<code>Err</code>], panics, or is |
| dropped, then the provided closure will never be invoked. The |
| <a href="trait.TryFuture.html#associatedtype.Error"><code>Error</code></a> type of this future and the future |
| returned by <code>f</code> have to match.</p> |
| <p>Note that this method consumes the future it is called on and returns a |
| wrapped version of it.</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::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Ok</span>::<i32, i32>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future = future.and_then(|x| <span class="kw">async move </span>{ <span class="prelude-val">Ok</span>::<i32, i32>(x + <span class="number">3</span>) }); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="number">4</span>));</code></pre></div> |
| <p>Calling <a href="trait.TryFutureExt.html#method.and_then"><code>and_then</code></a> on an errored future has no |
| effect:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Err</span>::<i32, i32>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future = future.and_then(|x| <span class="kw">async move </span>{ <span class="prelude-val">Err</span>::<i32, i32>(x + <span class="number">3</span>) }); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">1</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/future/try_future/mod.rs.html#440-444">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="struct.OrElse.html" title="struct futures::future::OrElse">OrElse</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="struct.OrElse.html" title="struct futures::future::OrElse">OrElse</a><Fut1, Fut2, F></span><code class="content"><span class="where fmt-newline">impl<Fut1, Fut2, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.OrElse.html" title="struct futures::future::OrElse">OrElse</a><Fut1, Fut2, F><span class="where fmt-newline">where<br> TryFlattenErr<<a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut1, F>, Fut2>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <TryFlattenErr<<a class="struct" href="struct.MapErr.html" title="struct futures::future::MapErr">MapErr</a><Fut1, F>, Fut2> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>) -> Fut,<br> Fut: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Ok = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>>,</span></h4></section></summary><div class="docblock"><p>Executes another future if this one resolves to an error. The |
| error value is passed to a closure to create this subsequent future.</p> |
| <p>The provided closure <code>f</code> will only be called if this future is resolved |
| to an [<code>Err</code>]. If this future resolves to an [<code>Ok</code>], panics, or is |
| dropped, then the provided closure will never be invoked. The |
| <a href="trait.TryFuture.html#associatedtype.Ok"><code>Ok</code></a> type of this future and the future returned by <code>f</code> |
| have to match.</p> |
| <p>Note that this method consumes the future it is called on and returns a |
| wrapped version of it.</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::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Err</span>::<i32, i32>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future = future.or_else(|x| <span class="kw">async move </span>{ <span class="prelude-val">Err</span>::<i32, i32>(x + <span class="number">3</span>) }); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">4</span>));</code></pre></div> |
| <p>Calling <a href="trait.TryFutureExt.html#method.or_else"><code>or_else</code></a> on a successful future has |
| no effect:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Ok</span>::<i32, i32>(<span class="number">1</span>) }; |
| <span class="kw">let </span>future = future.or_else(|x| <span class="kw">async move </span>{ <span class="prelude-val">Ok</span>::<i32, i32>(x + <span class="number">3</span>) }); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="number">1</span>));</code></pre></div> |
| </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/future/try_future/mod.rs.html#467-470">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="struct.InspectOk.html" title="struct futures::future::InspectOk">InspectOk</a><Self, 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="struct.InspectOk.html" title="struct futures::future::InspectOk">InspectOk</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.InspectOk.html" title="struct futures::future::InspectOk">InspectOk</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Inspect.html" title="struct futures::future::Inspect">Inspect</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, InspectOkFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Inspect.html" title="struct futures::future::Inspect">Inspect</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, InspectOkFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> F: FnOnce(&Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>),</span></h4></section></summary><div class="docblock"><p>Do something with the success value of a future before passing it on.</p> |
| <p>When using futures, you’ll often chain several of them together. While |
| working on such code, you might want to check out what’s happening at |
| various parts in the pipeline, without consuming the intermediate |
| value. To do that, insert a call to <code>inspect_ok</code>.</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::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Ok</span>::<<span class="kw">_</span>, ()>(<span class="number">1</span>) }; |
| <span class="kw">let </span>new_future = future.inspect_ok(|<span class="kw-2">&</span>x| <span class="macro">println!</span>(<span class="string">"about to resolve: {}"</span>, x)); |
| <span class="macro">assert_eq!</span>(new_future.<span class="kw">await</span>, <span class="prelude-val">Ok</span>(<span class="number">1</span>));</code></pre></div> |
| </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/future/try_future/mod.rs.html#493-496">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="struct.InspectErr.html" title="struct futures::future::InspectErr">InspectErr</a><Self, 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="struct.InspectErr.html" title="struct futures::future::InspectErr">InspectErr</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.InspectErr.html" title="struct futures::future::InspectErr">InspectErr</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Inspect.html" title="struct futures::future::Inspect">Inspect</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, InspectErrFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Inspect.html" title="struct futures::future::Inspect">Inspect</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, InspectErrFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> F: FnOnce(&Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>),</span></h4></section></summary><div class="docblock"><p>Do something with the error value of a future before passing it on.</p> |
| <p>When using futures, you’ll often chain several of them together. While |
| working on such code, you might want to check out what’s happening at |
| various parts in the pipeline, without consuming the intermediate |
| value. To do that, insert a call to <code>inspect_err</code>.</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::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Err</span>::<(), <span class="kw">_</span>>(<span class="number">1</span>) }; |
| <span class="kw">let </span>new_future = future.inspect_err(|<span class="kw-2">&</span>x| <span class="macro">println!</span>(<span class="string">"about to error: {}"</span>, x)); |
| <span class="macro">assert_eq!</span>(new_future.<span class="kw">await</span>, <span class="prelude-val">Err</span>(<span class="number">1</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/future/try_future/mod.rs.html#505-508">source</a><h4 class="code-header">fn <a href="#method.try_flatten" class="fnname">try_flatten</a>(self) -> <a class="struct" href="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><Self, Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>><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="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><Fut1, Fut2></span><code class="content"><span class="where fmt-newline">impl<Fut1, Fut2> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.TryFlatten.html" title="struct futures::future::TryFlatten">TryFlatten</a><Fut1, Fut2><span class="where fmt-newline">where<br> TryFlatten<Fut1, Fut2>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <TryFlatten<Fut1, Fut2> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a><Error = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>>,</span></h4></section></summary><div class="docblock"><p>Flatten the execution of this future when the successful result of this |
| future is another future.</p> |
| <p>This is equivalent to <code>future.and_then(|x| x)</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_flatten_stream" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/future/try_future/mod.rs.html#538-541">source</a><h4 class="code-header">fn <a href="#method.try_flatten_stream" class="fnname">try_flatten_stream</a>(self) -> <a class="struct" href="struct.TryFlattenStream.html" title="struct futures::future::TryFlattenStream">TryFlattenStream</a><Self><span class="where fmt-newline">where<br> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>: <a class="trait" href="../stream/trait.TryStream.html" title="trait futures::stream::TryStream">TryStream</a><Error = Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>>,</span></h4></section></summary><div class="docblock"><p>Flatten the execution of this future when the successful result of this |
| future is a stream.</p> |
| <p>This can be useful when stream initialization is deferred, and it is |
| convenient to work with that stream as if stream was available at the |
| call site.</p> |
| <p>Note that this function consumes this future and returns a wrapped |
| version of it.</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::future::TryFutureExt; |
| <span class="kw">use </span>futures::stream::{<span class="self">self</span>, TryStreamExt}; |
| |
| <span class="kw">let </span>stream_items = <span class="macro">vec!</span>[<span class="number">17</span>, <span class="number">18</span>, <span class="number">19</span>].into_iter().map(<span class="prelude-val">Ok</span>); |
| <span class="kw">let </span>future_of_a_stream = <span class="kw">async </span>{ <span class="prelude-val">Ok</span>::<<span class="kw">_</span>, ()>(stream::iter(stream_items)) }; |
| |
| <span class="kw">let </span>stream = future_of_a_stream.try_flatten_stream(); |
| <span class="kw">let </span>list = stream.try_collect::<Vec<<span class="kw">_</span>>>().<span class="kw">await</span>; |
| <span class="macro">assert_eq!</span>(list, <span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[<span class="number">17</span>, <span class="number">18</span>, <span class="number">19</span>]));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.unwrap_or_else" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/future/try_future/mod.rs.html#570-573">source</a><h4 class="code-header">fn <a href="#method.unwrap_or_else" class="fnname">unwrap_or_else</a><F>(self, f: F) -> <a class="struct" href="struct.UnwrapOrElse.html" title="struct futures::future::UnwrapOrElse">UnwrapOrElse</a><Self, 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="struct.UnwrapOrElse.html" title="struct futures::future::UnwrapOrElse">UnwrapOrElse</a><Fut, F></span><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.UnwrapOrElse.html" title="struct futures::future::UnwrapOrElse">UnwrapOrElse</a><Fut, F><span class="where fmt-newline">where<br> <a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, UnwrapOrElseFn<F>>: <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = <<a class="struct" href="struct.Map.html" title="struct futures::future::Map">Map</a><<a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut>, UnwrapOrElseFn<F>> as <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a>>::<a class="associatedtype" href="trait.Future.html#associatedtype.Output" title="type futures::future::Future::Output">Output</a>;</span></code></span></span></span></span><span class="where fmt-newline">where<br> F: FnOnce(Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>) -> Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>,</span></h4></section></summary><div class="docblock"><p>Unwraps this future’s output, producing a future with this future’s |
| <a href="trait.TryFuture.html#associatedtype.Ok"><code>Ok</code></a> type as its |
| <a href="trait.Future.html#associatedtype.Output"><code>Output</code></a> type.</p> |
| <p>If this future is resolved successfully, the returned future will |
| contain the original future’s success value as output. Otherwise, the |
| closure <code>f</code> is called with the error value to produce an alternate |
| success value.</p> |
| <p>This method is similar to the [<code>Result::unwrap_or_else</code>] method.</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::future::TryFutureExt; |
| |
| <span class="kw">let </span>future = <span class="kw">async </span>{ <span class="prelude-val">Err</span>::<(), <span class="kw-2">&</span>str>(<span class="string">"Boom!"</span>) }; |
| <span class="kw">let </span>future = future.unwrap_or_else(|<span class="kw">_</span>| ()); |
| <span class="macro">assert_eq!</span>(future.<span class="kw">await</span>, ());</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_future" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/future/try_future/mod.rs.html#610-612">source</a><h4 class="code-header">fn <a href="#method.into_future" class="fnname">into_future</a>(self) -> <a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</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="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut></span><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.IntoFuture.html" title="struct futures::future::IntoFuture">IntoFuture</a><Fut><span class="where fmt-newline">where<br> Fut: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>,</span></span><span class="where fmt-newline"> type <a href="trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = Result<<Fut as <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>>::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>, <Fut as <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a>>::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>>;</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Wraps a <a href="trait.TryFuture.html" title="TryFuture"><code>TryFuture</code></a> into a type that implements |
| <a href="trait.Future.html"><code>Future</code></a>.</p> |
| <p><a href="trait.TryFuture.html" title="TryFuture"><code>TryFuture</code></a>s currently do not implement the |
| <a href="trait.Future.html"><code>Future</code></a> trait due to limitations of the |
| compiler.</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::future::{Future, TryFuture, TryFutureExt}; |
| |
| <span class="kw">fn </span>make_try_future() -> <span class="kw">impl </span>TryFuture<<span class="prelude-val">Ok </span>= T, Error = E> { <span class="comment">// ... } |
| </span><span class="kw">fn </span>take_future(future: <span class="kw">impl </span>Future<Output = <span class="prelude-ty">Result</span><T, E>>) { <span class="comment">/* ... */ </span>} |
| |
| take_future(make_try_future().into_future());</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_poll_unpin" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/future/try_future/mod.rs.html#619-621">source</a><h4 class="code-header">fn <a href="#method.try_poll_unpin" class="fnname">try_poll_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><Result<Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Ok" title="type futures::future::TryFuture::Ok">Ok</a>, Self::<a class="associatedtype" href="trait.TryFuture.html#associatedtype.Error" title="type futures::future::TryFuture::Error">Error</a>>><span class="where fmt-newline">where<br> Self: Unpin,</span></h4></section></summary><div class="docblock"><p>A convenience method for calling <a href="trait.TryFuture.html#tymethod.try_poll" title="TryFuture::try_poll"><code>TryFuture::try_poll</code></a> on [<code>Unpin</code>] |
| future types.</p> |
| </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-TryFutureExt-for-Fut" class="impl has-srclink"><a class="srclink rightside" href="../../src/futures_util/future/try_future/mod.rs.html#134">source</a><a href="#impl-TryFutureExt-for-Fut" class="anchor"></a><h3 class="code-header">impl<Fut> <a class="trait" href="trait.TryFutureExt.html" title="trait futures::future::TryFutureExt">TryFutureExt</a> for Fut<span class="where fmt-newline">where<br> Fut: <a class="trait" href="trait.TryFuture.html" title="trait futures::future::TryFuture">TryFuture</a> + ?Sized,</span></h3></section></div><script src="../../implementors/futures_util/future/try_future/trait.TryFutureExt.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> |