mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-30 13:54:09 +01:00
280 lines
101 KiB
HTML
280 lines
101 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `FutureExt` trait in crate `futures_util`."><meta name="keywords" content="rust, rustlang, rust-lang, FutureExt"><title>futures_util::future::FutureExt - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../futures_util/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Trait FutureExt</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.map">map</a><a href="#method.poll_unpin">poll_unpin</a><a href="#method.boxed">boxed</a><a href="#method.flatten">flatten</a><a href="#method.fuse">fuse</a><a href="#method.catch_unwind">catch_unwind</a><a href="#method.remote_handle">remote_handle</a><a href="#method.shared">shared</a><a href="#method.map_into">map_into</a><a href="#method.then">then</a><a href="#method.left_future">left_future</a><a href="#method.right_future">right_future</a><a href="#method.into_stream">into_stream</a><a href="#method.flatten_stream">flatten_stream</a><a href="#method.inspect">inspect</a><a href="#method.boxed_local">boxed_local</a><a href="#method.unit_error">unit_error</a><a href="#method.never_error">never_error</a><a href="#method.now_or_never">now_or_never</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="../index.html">futures_util</a>::<wbr><a href="index.html">future</a></p><div id="sidebar-vars" data-name="FutureExt" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Trait <a href="../index.html">futures_util</a>::<wbr><a href="index.html">future</a>::<wbr><a class="trait" href="">FutureExt</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#123-610" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait FutureExt: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> {
|
||
fn <a href="#method.map" class="fnname">map</a><U, F>(self, f: F) -> <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Self, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, F></h3><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, F> <span class="where fmt-newline">where<br> Map<Fut, F>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <Map<Fut, F> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>) -> U,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.map_into" class="fnname">map_into</a><U>(self) -> <a class="struct" href="../../futures_util/future/struct.MapInto.html" title="struct futures_util::future::MapInto">MapInto</a><Self, U><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.MapInto.html" title="struct futures_util::future::MapInto">MapInto</a><Fut, T></h3><code class="content"><span class="where fmt-newline">impl<Fut, T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.MapInto.html" title="struct futures_util::future::MapInto">MapInto</a><Fut, T> <span class="where fmt-newline">where<br> <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, IntoFn<T>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, IntoFn<T>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.then" class="fnname">then</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures_util/future/struct.Then.html" title="struct futures_util::future::Then">Then</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Then.html" title="struct futures_util::future::Then">Then</a><Fut1, Fut2, F></h3><code class="content"><span class="where fmt-newline">impl<Fut1, Fut2, F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Then.html" title="struct futures_util::future::Then">Then</a><Fut1, Fut2, F> <span class="where fmt-newline">where<br> Flatten<<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut1, F>, Fut2>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <Flatten<<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut1, F>, Fut2> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>) -> Fut,<br> Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.left_future" class="fnname">left_future</a><B>(self) -> <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><Self, B><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, B></h3><code class="content"><span class="where fmt-newline">impl<A, B> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, B> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = A::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = A::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.right_future" class="fnname">right_future</a><A>(self) -> <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, B></h3><code class="content"><span class="where fmt-newline">impl<A, B> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, B> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = A::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = A::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.into_stream" class="fnname">into_stream</a>(self) -> <a class="struct" href="../../futures_util/future/struct.IntoStream.html" title="struct futures_util::future::IntoStream">IntoStream</a><Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.flatten" class="fnname">flatten</a>(self) -> <a class="struct" href="../../futures_util/future/struct.Flatten.html" title="struct futures_util::future::Flatten">Flatten</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Flatten.html" title="struct futures_util::future::Flatten">Flatten</a><F></h3><code class="content"><span class="where fmt-newline">impl<F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Flatten.html" title="struct futures_util::future::Flatten">Flatten</a><F> <span class="where fmt-newline">where<br> Flatten<F, <F as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <Flatten<F, <F as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.flatten_stream" class="fnname">flatten_stream</a>(self) -> <a class="struct" href="../../futures_util/future/struct.FlattenStream.html" title="struct futures_util::future::FlattenStream">FlattenStream</a><Self><br> <span class="where">where<br> Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="../../futures_util/stream/trait.Stream.html" title="trait futures_util::stream::Stream">Stream</a>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.fuse" class="fnname">fuse</a>(self) -> <a class="struct" href="../../futures_util/future/struct.Fuse.html" title="struct futures_util::future::Fuse">Fuse</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Fuse.html" title="struct futures_util::future::Fuse">Fuse</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Fuse.html" title="struct futures_util::future::Fuse">Fuse</a><Fut></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = Fut::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.inspect" class="fnname">inspect</a><F>(self, f: F) -> <a class="struct" href="../../futures_util/future/struct.Inspect.html" title="struct futures_util::future::Inspect">Inspect</a><Self, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Inspect.html" title="struct futures_util::future::Inspect">Inspect</a><Fut, F></h3><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Inspect.html" title="struct futures_util::future::Inspect">Inspect</a><Fut, F> <span class="where fmt-newline">where<br> Map<Fut, InspectFn<F>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <Map<Fut, InspectFn<F>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>),<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.catch_unwind" class="fnname">catch_unwind</a>(self) -> <a class="struct" href="../../futures_util/future/struct.CatchUnwind.html" title="struct futures_util::future::CatchUnwind">CatchUnwind</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.CatchUnwind.html" title="struct futures_util::future::CatchUnwind">CatchUnwind</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.CatchUnwind.html" title="struct futures_util::future::CatchUnwind">CatchUnwind</a><Fut> <span class="where fmt-newline">where<br> Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Fut::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>>>;</span></code></span></div></span></span><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.shared" class="fnname">shared</a>(self) -> <a class="struct" href="../../futures_util/future/struct.Shared.html" title="struct futures_util::future::Shared">Shared</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Shared.html" title="struct futures_util::future::Shared">Shared</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Shared.html" title="struct futures_util::future::Shared">Shared</a><Fut> <span class="where fmt-newline">where<br> Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> Fut::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = Fut::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br> Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.remote_handle" class="fnname">remote_handle</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="struct" href="../../futures_util/future/struct.Remote.html" title="struct futures_util::future::Remote">Remote</a><Self>, <a class="struct" href="../../futures_util/future/struct.RemoteHandle.html" title="struct futures_util::future::RemoteHandle">RemoteHandle</a><Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.boxed" class="fnname">boxed</a><'a>(self) -> <a class="type" href="../../futures_util/future/type.BoxFuture.html" title="type futures_util::future::BoxFuture">BoxFuture</a><'a, Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'a</span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.boxed_local" class="fnname">boxed_local</a><'a>(self) -> <a class="type" href="../../futures_util/future/type.LocalBoxFuture.html" title="type futures_util::future::LocalBoxFuture">LocalBoxFuture</a><'a, Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a</span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.unit_error" class="fnname">unit_error</a>(self) -> <a class="struct" href="../../futures_util/future/struct.UnitError.html" title="struct futures_util::future::UnitError">UnitError</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.UnitError.html" title="struct futures_util::future::UnitError">UnitError</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.UnitError.html" title="struct futures_util::future::UnitError">UnitError</a><Fut> <span class="where fmt-newline">where<br> <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, OkFn<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, OkFn<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.never_error" class="fnname">never_error</a>(self) -> <a class="struct" href="../../futures_util/future/struct.NeverError.html" title="struct futures_util::future::NeverError">NeverError</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.NeverError.html" title="struct futures_util::future::NeverError">NeverError</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.NeverError.html" title="struct futures_util::future::NeverError">NeverError</a><Fut> <span class="where fmt-newline">where<br> <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, OkFn<<a class="type" href="../../futures_util/never/type.Never.html" title="type futures_util::never::Never">Never</a>>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, OkFn<<a class="type" href="../../futures_util/never/type.Never.html" title="type futures_util::never::Never">Never</a>>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.poll_unpin" class="fnname">poll_unpin</a>(&mut self, cx: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a><'_>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a><Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>,
|
||
{ ... }
|
||
<div class="item-spacer"></div> fn <a href="#method.now_or_never" class="fnname">now_or_never</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
|
||
{ ... }
|
||
}</pre></div><div class="docblock"><p>An extension trait for <code>Future</code>s that provides a variety of convenient
|
||
adapters.</p>
|
||
</div><h2 id="provided-methods" class="small-section-header">Provided methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><h3 id="method.map" class="method"><code>fn <a href="#method.map" class="fnname">map</a><U, F>(self, f: F) -> <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Self, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, F></h3><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, F> <span class="where fmt-newline">where<br> Map<Fut, F>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <Map<Fut, F> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>) -> U,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#146-152" title="goto source code">[src]</a></h3><div class="docblock"><p>Map this future's output to a different type, returning a new future of
|
||
the resulting type.</p>
|
||
<p>This function is similar to the <code>Option::map</code> or <code>Iterator::map</code> where
|
||
it will change the type of the underlying future. This is useful to
|
||
chain along a computation once a future has been resolved.</p>
|
||
<p>Note that this function consumes the receiving future and returns a
|
||
wrapped version of it, similar to the existing <code>map</code> methods in the
|
||
standard library.</p>
|
||
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="kw">async</span> { <span class="number">1</span> };
|
||
<span class="kw">let</span> <span class="ident">new_future</span> <span class="op">=</span> <span class="ident">future</span>.<span class="ident">map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">+</span> <span class="number">3</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">new_future</span>.<span class="kw">await</span>, <span class="number">4</span>);</pre></div>
|
||
</div><h3 id="method.map_into" class="method"><code>fn <a href="#method.map_into" class="fnname">map_into</a><U>(self) -> <a class="struct" href="../../futures_util/future/struct.MapInto.html" title="struct futures_util::future::MapInto">MapInto</a><Self, U><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.MapInto.html" title="struct futures_util::future::MapInto">MapInto</a><Fut, T></h3><code class="content"><span class="where fmt-newline">impl<Fut, T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.MapInto.html" title="struct futures_util::future::MapInto">MapInto</a><Fut, T> <span class="where fmt-newline">where<br> <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, IntoFn<T>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, IntoFn<T>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#159-165" title="goto source code">[src]</a></h3><div class="docblock"><p>Map this future's output to a different type, returning a new future of
|
||
the resulting type.</p>
|
||
<p>This function is equivalent to calling <code>map(Into::into)</code> but allows naming
|
||
the return type.</p>
|
||
</div><h3 id="method.then" class="method"><code>fn <a href="#method.then" class="fnname">then</a><Fut, F>(self, f: F) -> <a class="struct" href="../../futures_util/future/struct.Then.html" title="struct futures_util::future::Then">Then</a><Self, Fut, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Then.html" title="struct futures_util::future::Then">Then</a><Fut1, Fut2, F></h3><code class="content"><span class="where fmt-newline">impl<Fut1, Fut2, F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Then.html" title="struct futures_util::future::Then">Then</a><Fut1, Fut2, F> <span class="where fmt-newline">where<br> Flatten<<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut1, F>, Fut2>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <Flatten<<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut1, F>, Fut2> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>) -> Fut,<br> Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#191-198" title="goto source code">[src]</a></h3><div class="docblock"><p>Chain on a computation for when a future finished, passing the result of
|
||
the future to the provided closure <code>f</code>.</p>
|
||
<p>The returned value of the closure must implement the <code>Future</code> trait
|
||
and can represent some more work to be done before the composed future
|
||
is finished.</p>
|
||
<p>The closure <code>f</code> is only run <em>after</em> successful completion of the <code>self</code>
|
||
future.</p>
|
||
<p>Note that this function consumes the receiving future and returns a
|
||
wrapped version of it.</p>
|
||
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">future_of_1</span> <span class="op">=</span> <span class="kw">async</span> { <span class="number">1</span> };
|
||
<span class="kw">let</span> <span class="ident">future_of_4</span> <span class="op">=</span> <span class="ident">future_of_1</span>.<span class="ident">then</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> { <span class="ident">x</span> <span class="op">+</span> <span class="number">3</span> });
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">future_of_4</span>.<span class="kw">await</span>, <span class="number">4</span>);</pre></div>
|
||
</div><h3 id="method.left_future" class="method"><code>fn <a href="#method.left_future" class="fnname">left_future</a><B>(self) -> <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><Self, B><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, B></h3><code class="content"><span class="where fmt-newline">impl<A, B> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, B> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = A::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = A::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#222-228" title="goto source code">[src]</a></h3><div class="docblock"><p>Wrap this future in an <code>Either</code> future, making it the left-hand variant
|
||
of that <code>Either</code>.</p>
|
||
<p>This can be used in combination with the <code>right_future</code> method to write <code>if</code>
|
||
statements that evaluate to different futures in different branches.</p>
|
||
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">6</span>;
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="kw">if</span> <span class="ident">x</span> <span class="op"><</span> <span class="number">10</span> {
|
||
<span class="kw">async</span> { <span class="bool-val">true</span> }.<span class="ident">left_future</span>()
|
||
} <span class="kw">else</span> {
|
||
<span class="kw">async</span> { <span class="bool-val">false</span> }.<span class="ident">right_future</span>()
|
||
};
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">future</span>.<span class="kw">await</span>, <span class="bool-val">true</span>);</pre></div>
|
||
</div><h3 id="method.right_future" class="method"><code>fn <a href="#method.right_future" class="fnname">right_future</a><A>(self) -> <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, B></h3><code class="content"><span class="where fmt-newline">impl<A, B> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="enum" href="../../futures_util/future/enum.Either.html" title="enum futures_util::future::Either">Either</a><A, B> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = A::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = A::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#252-258" title="goto source code">[src]</a></h3><div class="docblock"><p>Wrap this future in an <code>Either</code> future, making it the right-hand variant
|
||
of that <code>Either</code>.</p>
|
||
<p>This can be used in combination with the <code>left_future</code> method to write <code>if</code>
|
||
statements that evaluate to different futures in different branches.</p>
|
||
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="number">6</span>;
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="kw">if</span> <span class="ident">x</span> <span class="op">></span> <span class="number">10</span> {
|
||
<span class="kw">async</span> { <span class="bool-val">true</span> }.<span class="ident">left_future</span>()
|
||
} <span class="kw">else</span> {
|
||
<span class="kw">async</span> { <span class="bool-val">false</span> }.<span class="ident">right_future</span>()
|
||
};
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">future</span>.<span class="kw">await</span>, <span class="bool-val">false</span>);</pre></div>
|
||
</div><h3 id="method.into_stream" class="method"><code>fn <a href="#method.into_stream" class="fnname">into_stream</a>(self) -> <a class="struct" href="../../futures_util/future/struct.IntoStream.html" title="struct futures_util::future::IntoStream">IntoStream</a><Self> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#278-283" title="goto source code">[src]</a></h3><div class="docblock"><p>Convert this future into a single element stream.</p>
|
||
<p>The returned stream contains single success if this future resolves to
|
||
success or single error if this future resolves into error.</p>
|
||
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::<span class="ident">StreamExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="kw">async</span> { <span class="number">17</span> };
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">future</span>.<span class="ident">into_stream</span>();
|
||
<span class="kw">let</span> <span class="ident">collected</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">collect</span>().<span class="kw">await</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">collected</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">17</span>]);</pre></div>
|
||
</div><h3 id="method.flatten" class="method"><code>fn <a href="#method.flatten" class="fnname">flatten</a>(self) -> <a class="struct" href="../../futures_util/future/struct.Flatten.html" title="struct futures_util::future::Flatten">Flatten</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Flatten.html" title="struct futures_util::future::Flatten">Flatten</a><F></h3><code class="content"><span class="where fmt-newline">impl<F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Flatten.html" title="struct futures_util::future::Flatten">Flatten</a><F> <span class="where fmt-newline">where<br> Flatten<F, <F as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <Flatten<F, <F as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#307-314" title="goto source code">[src]</a></h3><div class="docblock"><p>Flatten the execution of this future when the output of this
|
||
future is itself another future.</p>
|
||
<p>This can be useful when combining futures together to flatten the
|
||
computation out the final result.</p>
|
||
<p>This method is roughly equivalent to <code>self.then(|x| x)</code>.</p>
|
||
<p>Note that this function consumes the receiving future and returns a
|
||
wrapped version of it.</p>
|
||
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">nested_future</span> <span class="op">=</span> <span class="kw">async</span> { <span class="kw">async</span> { <span class="number">1</span> } };
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="ident">nested_future</span>.<span class="ident">flatten</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">future</span>.<span class="kw">await</span>, <span class="number">1</span>);</pre></div>
|
||
</div><h3 id="method.flatten_stream" class="method"><code>fn <a href="#method.flatten_stream" class="fnname">flatten_stream</a>(self) -> <a class="struct" href="../../futures_util/future/struct.FlattenStream.html" title="struct futures_util::future::FlattenStream">FlattenStream</a><Self> <span class="where fmt-newline">where<br> Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="../../futures_util/stream/trait.Stream.html" title="trait futures_util::stream::Stream">Stream</a>,<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#341-347" title="goto source code">[src]</a></h3><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>
|
||
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">stream</span>::{<span class="self">self</span>, <span class="ident">StreamExt</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">stream_items</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">17</span>, <span class="number">18</span>, <span class="number">19</span>];
|
||
<span class="kw">let</span> <span class="ident">future_of_a_stream</span> <span class="op">=</span> <span class="kw">async</span> { <span class="ident">stream</span>::<span class="ident">iter</span>(<span class="ident">stream_items</span>) };
|
||
|
||
<span class="kw">let</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">future_of_a_stream</span>.<span class="ident">flatten_stream</span>();
|
||
<span class="kw">let</span> <span class="ident">list</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">collect</span>().<span class="kw">await</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">list</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">17</span>, <span class="number">18</span>, <span class="number">19</span>]);</pre></div>
|
||
</div><h3 id="method.fuse" class="method"><code>fn <a href="#method.fuse" class="fnname">fuse</a>(self) -> <a class="struct" href="../../futures_util/future/struct.Fuse.html" title="struct futures_util::future::Fuse">Fuse</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Fuse.html" title="struct futures_util::future::Fuse">Fuse</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Fuse.html" title="struct futures_util::future::Fuse">Fuse</a><Fut></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = Fut::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#365-371" title="goto source code">[src]</a></h3><div class="docblock"><p>Fuse a future such that <code>poll</code> will never again be called once it has
|
||
completed. This method can be used to turn any <code>Future</code> into a
|
||
<code>FusedFuture</code>.</p>
|
||
<p>Normally, once a future has returned <code>Poll::Ready</code> from <code>poll</code>,
|
||
any further calls could exhibit bad behavior such as blocking
|
||
forever, panicking, never returning, etc. If it is known that <code>poll</code>
|
||
may be called too often then this method can be used to ensure that it
|
||
has defined semantics.</p>
|
||
<p>If a <code>fuse</code>d future is <code>poll</code>ed after having returned <code>Poll::Ready</code>
|
||
previously, it will return <code>Poll::Pending</code>, from <code>poll</code> again (and will
|
||
continue to do so for all future calls to <code>poll</code>).</p>
|
||
<p>This combinator will drop the underlying future as soon as it has been
|
||
completed to ensure resources are reclaimed as soon as possible.</p>
|
||
</div><h3 id="method.inspect" class="method"><code>fn <a href="#method.inspect" class="fnname">inspect</a><F>(self, f: F) -> <a class="struct" href="../../futures_util/future/struct.Inspect.html" title="struct futures_util::future::Inspect">Inspect</a><Self, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Inspect.html" title="struct futures_util::future::Inspect">Inspect</a><Fut, F></h3><code class="content"><span class="where fmt-newline">impl<Fut, F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Inspect.html" title="struct futures_util::future::Inspect">Inspect</a><Fut, F> <span class="where fmt-newline">where<br> Map<Fut, InspectFn<F>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <Map<Fut, InspectFn<F>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>),<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#391-397" title="goto source code">[src]</a></h3><div class="docblock"><p>Do something with the output 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</code>.</p>
|
||
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="kw">async</span> { <span class="number">1</span> };
|
||
<span class="kw">let</span> <span class="ident">new_future</span> <span class="op">=</span> <span class="ident">future</span>.<span class="ident">inspect</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"about to resolve: {}"</span>, <span class="ident">x</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">new_future</span>.<span class="kw">await</span>, <span class="number">1</span>);</pre></div>
|
||
</div><h3 id="method.catch_unwind" class="method"><code>fn <a href="#method.catch_unwind" class="fnname">catch_unwind</a>(self) -> <a class="struct" href="../../futures_util/future/struct.CatchUnwind.html" title="struct futures_util::future::CatchUnwind">CatchUnwind</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.CatchUnwind.html" title="struct futures_util::future::CatchUnwind">CatchUnwind</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.CatchUnwind.html" title="struct futures_util::future::CatchUnwind">CatchUnwind</a><Fut> <span class="where fmt-newline">where<br> Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Fut::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>>>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#431-438" title="goto source code">[src]</a></h3><div class="docblock"><p>Catches unwinding panics while polling the future.</p>
|
||
<p>In general, panics within a future can propagate all the way out to the
|
||
task level. This combinator makes it possible to halt unwinding within
|
||
the future itself. It's most commonly used within task executors. It's
|
||
not recommended to use this for error handling.</p>
|
||
<p>Note that this method requires the <code>UnwindSafe</code> bound from the standard
|
||
library. This isn't always applied automatically, and the standard
|
||
library provides an <code>AssertUnwindSafe</code> wrapper type to apply it
|
||
after-the fact. To assist using this method, the <code>Future</code> trait is also
|
||
implemented for <code>AssertUnwindSafe<F></code> where <code>F</code> implements <code>Future</code>.</p>
|
||
<p>This method is only available when the <code>std</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::{<span class="self">self</span>, <span class="ident">FutureExt</span>, <span class="ident">Ready</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="ident">future</span>::<span class="ident">ready</span>(<span class="number">2</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">future</span>.<span class="ident">catch_unwind</span>().<span class="kw">await</span>.<span class="ident">is_ok</span>());
|
||
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="ident">future</span>::<span class="ident">lazy</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> <span class="op">-</span><span class="op">></span> <span class="ident">Ready</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> {
|
||
<span class="macro">unimplemented</span><span class="macro">!</span>()
|
||
});
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">future</span>.<span class="ident">catch_unwind</span>().<span class="kw">await</span>.<span class="ident">is_err</span>());</pre></div>
|
||
</div><h3 id="method.shared" class="method"><code>fn <a href="#method.shared" class="fnname">shared</a>(self) -> <a class="struct" href="../../futures_util/future/struct.Shared.html" title="struct futures_util::future::Shared">Shared</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.Shared.html" title="struct futures_util::future::Shared">Shared</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.Shared.html" title="struct futures_util::future::Shared">Shared</a><Fut> <span class="where fmt-newline">where<br> Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,<br> Fut::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = Fut::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br> Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#486-492" title="goto source code">[src]</a></h3><div class="docblock"><p>Create a cloneable handle to this future where all handles will resolve
|
||
to the same result.</p>
|
||
<p>The <code>shared</code> combinator method provides a method to convert any future
|
||
into a cloneable future. It enables a future to be polled by multiple
|
||
threads.</p>
|
||
<p>This method is only available when the <code>std</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
<h1 id="examples-9" class="section-header"><a href="#examples-9">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="kw">async</span> { <span class="number">6</span> };
|
||
<span class="kw">let</span> <span class="ident">shared1</span> <span class="op">=</span> <span class="ident">future</span>.<span class="ident">shared</span>();
|
||
<span class="kw">let</span> <span class="ident">shared2</span> <span class="op">=</span> <span class="ident">shared1</span>.<span class="ident">clone</span>();
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">6</span>, <span class="ident">shared1</span>.<span class="kw">await</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">6</span>, <span class="ident">shared2</span>.<span class="kw">await</span>);</pre></div>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="comment">// Note, unlike most examples this is written in the context of a</span>
|
||
<span class="comment">// synchronous function to better illustrate the cross-thread aspect of</span>
|
||
<span class="comment">// the `shared` combinator.</span>
|
||
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">future</span>::<span class="ident">FutureExt</span>;
|
||
<span class="kw">use</span> <span class="ident">futures</span>::<span class="ident">executor</span>::<span class="ident">block_on</span>;
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">thread</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">future</span> <span class="op">=</span> <span class="kw">async</span> { <span class="number">6</span> };
|
||
<span class="kw">let</span> <span class="ident">shared1</span> <span class="op">=</span> <span class="ident">future</span>.<span class="ident">shared</span>();
|
||
<span class="kw">let</span> <span class="ident">shared2</span> <span class="op">=</span> <span class="ident">shared1</span>.<span class="ident">clone</span>();
|
||
<span class="kw">let</span> <span class="ident">join_handle</span> <span class="op">=</span> <span class="ident">thread</span>::<span class="ident">spawn</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">6</span>, <span class="ident">block_on</span>(<span class="ident">shared2</span>));
|
||
});
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">6</span>, <span class="ident">shared1</span>.<span class="kw">await</span>);
|
||
<span class="ident">join_handle</span>.<span class="ident">join</span>().<span class="ident">unwrap</span>();</pre></div>
|
||
</div><h3 id="method.remote_handle" class="method"><code>fn <a href="#method.remote_handle" class="fnname">remote_handle</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="struct" href="../../futures_util/future/struct.Remote.html" title="struct futures_util::future::Remote">Remote</a><Self>, <a class="struct" href="../../futures_util/future/struct.RemoteHandle.html" title="struct futures_util::future::RemoteHandle">RemoteHandle</a><Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#505-511" title="goto source code">[src]</a></h3><div class="docblock"><p>Turn this future into a future that yields <code>()</code> on completion and sends
|
||
its output to another future on a separate task.</p>
|
||
<p>This can be used with spawning executors to easily retrieve the result
|
||
of a future executing on a separate task or thread.</p>
|
||
<p>This method is only available when the <code>std</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
</div><h3 id="method.boxed" class="method"><code>fn <a href="#method.boxed" class="fnname">boxed</a><'a>(self) -> <a class="type" href="../../futures_util/future/type.BoxFuture.html" title="type futures_util::future::BoxFuture">BoxFuture</a><'a, Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'a, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#518-523" title="goto source code">[src]</a></h3><div class="docblock"><p>Wrap the future in a Box, pinning it.</p>
|
||
<p>This method is only available when the <code>std</code> or <code>alloc</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
</div><h3 id="method.boxed_local" class="method"><code>fn <a href="#method.boxed_local" class="fnname">boxed_local</a><'a>(self) -> <a class="type" href="../../futures_util/future/type.LocalBoxFuture.html" title="type futures_util::future::LocalBoxFuture">LocalBoxFuture</a><'a, Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#532-537" title="goto source code">[src]</a></h3><div class="docblock"><p>Wrap the future in a Box, pinning it.</p>
|
||
<p>Similar to <code>boxed</code>, but without the <code>Send</code> requirement.</p>
|
||
<p>This method is only available when the <code>std</code> or <code>alloc</code> feature of this
|
||
library is activated, and it is activated by default.</p>
|
||
</div><h3 id="method.unit_error" class="method"><code>fn <a href="#method.unit_error" class="fnname">unit_error</a>(self) -> <a class="struct" href="../../futures_util/future/struct.UnitError.html" title="struct futures_util::future::UnitError">UnitError</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.UnitError.html" title="struct futures_util::future::UnitError">UnitError</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.UnitError.html" title="struct futures_util::future::UnitError">UnitError</a><Fut> <span class="where fmt-newline">where<br> <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, OkFn<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, OkFn<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#541-546" title="goto source code">[src]</a></h3><div class="docblock"><p>Turns a <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html"><code>Future<Output = T></code></a> into a
|
||
<a href="../../futures_util/future/trait.TryFuture.html"><code>TryFuture<Ok = T, Error = ()</code>></a>.</p>
|
||
</div><h3 id="method.never_error" class="method"><code>fn <a href="#method.never_error" class="fnname">never_error</a>(self) -> <a class="struct" href="../../futures_util/future/struct.NeverError.html" title="struct futures_util::future::NeverError">NeverError</a><Self><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../../futures_util/future/struct.NeverError.html" title="struct futures_util::future::NeverError">NeverError</a><Fut></h3><code class="content"><span class="where fmt-newline">impl<Fut> <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> for <a class="struct" href="../../futures_util/future/struct.NeverError.html" title="struct futures_util::future::NeverError">NeverError</a><Fut> <span class="where fmt-newline">where<br> <a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, OkFn<<a class="type" href="../../futures_util/never/type.Never.html" title="type futures_util::never::Never">Never</a>>>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" class="type">Output</a> = <<a class="struct" href="../../futures_util/future/struct.Map.html" title="struct futures_util::future::Map">Map</a><Fut, OkFn<<a class="type" href="../../futures_util/never/type.Never.html" title="type futures_util::never::Never">Never</a>>> as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>;</span></code></span></div></span></span> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#550-555" title="goto source code">[src]</a></h3><div class="docblock"><p>Turns a <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html"><code>Future<Output = T></code></a> into a
|
||
<a href="../../futures_util/future/trait.TryFuture.html"><code>TryFuture<Ok = T, Error = Never</code>></a>.</p>
|
||
</div><h3 id="method.poll_unpin" class="method"><code>fn <a href="#method.poll_unpin" class="fnname">poll_unpin</a>(&mut self, cx: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a><'_>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a><Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#558-563" title="goto source code">[src]</a></h3><div class="docblock"><p>A convenience for calling <code>Future::poll</code> on <code>Unpin</code> future types.</p>
|
||
</div><h3 id="method.now_or_never" class="method"><code>fn <a href="#method.now_or_never" class="fnname">now_or_never</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> <span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#596-609" title="goto source code">[src]</a></h3><div class="docblock"><p>Evaluates and consumes the future, returning the resulting output if
|
||
the future is ready after the first call to <code>Future::poll</code>.</p>
|
||
<p>If <code>poll</code> instead returns <code>Poll::Pending</code>, <code>None</code> is returned.</p>
|
||
<p>This method is useful in cases where immediacy is more important than
|
||
waiting for a result. It is also convenient for quickly obtaining
|
||
the value of a future that is known to always resolve immediately.</p>
|
||
<h1 id="examples-10" class="section-header"><a href="#examples-10">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">futures</span>::{<span class="ident">future</span>::<span class="ident">ready</span>, <span class="ident">future</span>::<span class="ident">pending</span>};
|
||
<span class="kw">let</span> <span class="ident">future_ready</span> <span class="op">=</span> <span class="ident">ready</span>(<span class="string">"foobar"</span>);
|
||
<span class="kw">let</span> <span class="ident">future_pending</span> <span class="op">=</span> <span class="ident">pending</span>::<span class="op"><</span><span class="kw-2">&</span><span class="lifetime">'static</span> <span class="ident">str</span><span class="op">></span>();
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">future_ready</span>.<span class="ident">now_or_never</span>(), <span class="prelude-val">Some</span>(<span class="string">"foobar"</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">future_pending</span>.<span class="ident">now_or_never</span>(), <span class="prelude-val">None</span>);</pre></div>
|
||
<p>In cases where it is absolutely known that a future should always
|
||
resolve immediately and never return <code>Poll::Pending</code>, this method can
|
||
be combined with <code>expect()</code>:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">let</span> <span class="ident">future_ready</span> <span class="op">=</span> <span class="ident">ready</span>(<span class="string">"foobar"</span>);
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">future_ready</span>.<span class="ident">now_or_never</span>().<span class="ident">expect</span>(<span class="string">"Future not ready"</span>), <span class="string">"foobar"</span>);</pre></div>
|
||
</div></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><h3 id="impl-FutureExt" class="impl"><code class="in-band">impl<T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>> FutureExt for T <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>, </span></code><a href="#impl-FutureExt" class="anchor"></a><a class="srclink" href="../../src/futures_util/future/future/mod.rs.html#119" title="goto source code">[src]</a></h3><div class="impl-items"></div></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../../implementors/futures_util/future/trait.FutureExt.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="futures_util"></div>
|
||
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html> |