/rust/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/common/lazy.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use pin_project_lite::pin_project; |
2 | | |
3 | | use std::future::Future; |
4 | | use std::pin::Pin; |
5 | | use std::task::{self, Poll}; |
6 | | |
7 | | pub(crate) trait Started: Future { |
8 | | fn started(&self) -> bool; |
9 | | } |
10 | | |
11 | 0 | pub(crate) fn lazy<F, R>(func: F) -> Lazy<F, R> |
12 | 0 | where |
13 | 0 | F: FnOnce() -> R, |
14 | 0 | R: Future + Unpin, |
15 | 0 | { |
16 | 0 | Lazy { |
17 | 0 | inner: Inner::Init { func }, |
18 | 0 | } |
19 | 0 | } Unexecuted instantiation: hyper_util::common::lazy::lazy::<<hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}, futures_util::future::either::Either<futures_util::future::try_future::AndThen<futures_util::future::try_future::MapErr<hyper_util::service::oneshot::Oneshot<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http::uri::Uri>, <hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#0}>, futures_util::future::either::Either<core::pin::Pin<alloc::boxed::Box<<hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#1}::{closure#0}>>, futures_util::future::ready::Ready<core::result::Result<hyper_util::client::legacy::pool::Pooled<hyper_util::client::legacy::client::PoolClient<http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>, (http::uri::scheme::Scheme, http::uri::authority::Authority)>, hyper_util::client::legacy::client::Error>>>, <hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#1}>, futures_util::future::ready::Ready<core::result::Result<hyper_util::client::legacy::pool::Pooled<hyper_util::client::legacy::client::PoolClient<http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>, (http::uri::scheme::Scheme, http::uri::authority::Authority)>, hyper_util::client::legacy::client::Error>>>> Unexecuted instantiation: hyper_util::common::lazy::lazy::<_, _> |
20 | | |
21 | | // FIXME: allow() required due to `impl Trait` leaking types to this lint |
22 | | pin_project! { |
23 | | #[allow(missing_debug_implementations)] |
24 | | pub(crate) struct Lazy<F, R> { |
25 | | #[pin] |
26 | | inner: Inner<F, R>, |
27 | | } |
28 | | } |
29 | | |
30 | | pin_project! { |
31 | | #[project = InnerProj] |
32 | | #[project_replace = InnerProjReplace] |
33 | | enum Inner<F, R> { |
34 | | Init { func: F }, |
35 | | Fut { #[pin] fut: R }, |
36 | | Empty, |
37 | | } |
38 | | } |
39 | | |
40 | | impl<F, R> Started for Lazy<F, R> |
41 | | where |
42 | | F: FnOnce() -> R, |
43 | | R: Future, |
44 | | { |
45 | 0 | fn started(&self) -> bool { |
46 | 0 | match self.inner { |
47 | 0 | Inner::Init { .. } => false, |
48 | 0 | Inner::Fut { .. } | Inner::Empty => true, |
49 | | } |
50 | 0 | } Unexecuted instantiation: <hyper_util::common::lazy::Lazy<<hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}, futures_util::future::either::Either<futures_util::future::try_future::AndThen<futures_util::future::try_future::MapErr<hyper_util::service::oneshot::Oneshot<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http::uri::Uri>, <hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#0}>, futures_util::future::either::Either<core::pin::Pin<alloc::boxed::Box<<hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#1}::{closure#0}>>, futures_util::future::ready::Ready<core::result::Result<hyper_util::client::legacy::pool::Pooled<hyper_util::client::legacy::client::PoolClient<http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>, (http::uri::scheme::Scheme, http::uri::authority::Authority)>, hyper_util::client::legacy::client::Error>>>, <hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#1}>, futures_util::future::ready::Ready<core::result::Result<hyper_util::client::legacy::pool::Pooled<hyper_util::client::legacy::client::PoolClient<http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>, (http::uri::scheme::Scheme, http::uri::authority::Authority)>, hyper_util::client::legacy::client::Error>>>> as hyper_util::common::lazy::Started>::started Unexecuted instantiation: <hyper_util::common::lazy::Lazy<_, _> as hyper_util::common::lazy::Started>::started |
51 | | } |
52 | | |
53 | | impl<F, R> Future for Lazy<F, R> |
54 | | where |
55 | | F: FnOnce() -> R, |
56 | | R: Future, |
57 | | { |
58 | | type Output = R::Output; |
59 | | |
60 | 0 | fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> { |
61 | 0 | let mut this = self.project(); |
62 | | |
63 | 0 | if let InnerProj::Fut { fut } = this.inner.as_mut().project() { |
64 | 0 | return fut.poll(cx); |
65 | 0 | } |
66 | 0 |
|
67 | 0 | match this.inner.as_mut().project_replace(Inner::Empty) { |
68 | 0 | InnerProjReplace::Init { func } => { |
69 | 0 | this.inner.set(Inner::Fut { fut: func() }); |
70 | 0 | if let InnerProj::Fut { fut } = this.inner.project() { |
71 | 0 | return fut.poll(cx); |
72 | 0 | } |
73 | 0 | unreachable!() |
74 | | } |
75 | 0 | _ => unreachable!("lazy state wrong"), |
76 | | } |
77 | 0 | } Unexecuted instantiation: <hyper_util::common::lazy::Lazy<<hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}, futures_util::future::either::Either<futures_util::future::try_future::AndThen<futures_util::future::try_future::MapErr<hyper_util::service::oneshot::Oneshot<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http::uri::Uri>, <hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#0}>, futures_util::future::either::Either<core::pin::Pin<alloc::boxed::Box<<hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#1}::{closure#0}>>, futures_util::future::ready::Ready<core::result::Result<hyper_util::client::legacy::pool::Pooled<hyper_util::client::legacy::client::PoolClient<http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>, (http::uri::scheme::Scheme, http::uri::authority::Authority)>, hyper_util::client::legacy::client::Error>>>, <hyper_util::client::legacy::client::Client<hyper_rustls::connector::HttpsConnector<hyper_util::client::legacy::connect::http::HttpConnector>, http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>>::connect_to::{closure#0}::{closure#1}>, futures_util::future::ready::Ready<core::result::Result<hyper_util::client::legacy::pool::Pooled<hyper_util::client::legacy::client::PoolClient<http_body_util::combinators::box_body::UnsyncBoxBody<bytes::bytes::Bytes, tonic::status::Status>>, (http::uri::scheme::Scheme, http::uri::authority::Authority)>, hyper_util::client::legacy::client::Error>>>> as core::future::future::Future>::poll Unexecuted instantiation: <hyper_util::common::lazy::Lazy<_, _> as core::future::future::Future>::poll |
78 | | } |