From ac0f894dd9be2a3a7e86405607ae240e9bc0a770 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 13 Feb 2022 04:54:45 +0900 Subject: [PATCH] net: use std::future::ready instead of own Ready future (#4271) --- tokio/src/future/mod.rs | 5 ----- tokio/src/future/ready.rs | 27 --------------------------- tokio/src/net/addr.rs | 9 ++++----- 3 files changed, 4 insertions(+), 37 deletions(-) delete mode 100644 tokio/src/future/ready.rs diff --git a/tokio/src/future/mod.rs b/tokio/src/future/mod.rs index 96483acd7c4..084ddc571f5 100644 --- a/tokio/src/future/mod.rs +++ b/tokio/src/future/mod.rs @@ -8,11 +8,6 @@ pub(crate) mod maybe_done; mod poll_fn; pub use poll_fn::poll_fn; -cfg_not_loom! { - mod ready; - pub(crate) use ready::{ok, Ready}; -} - cfg_process! { mod try_join; pub(crate) use try_join::try_join3; diff --git a/tokio/src/future/ready.rs b/tokio/src/future/ready.rs deleted file mode 100644 index de2d60c13a2..00000000000 --- a/tokio/src/future/ready.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::future::Future; -use std::pin::Pin; -use std::task::{Context, Poll}; - -/// Future for the [`ok`](ok()) function. -/// -/// `pub` in order to use the future as an associated type in a sealed trait. -#[derive(Debug)] -// Used as an associated type in a "sealed" trait. -#[allow(unreachable_pub)] -pub struct Ready(Option); - -impl Unpin for Ready {} - -impl Future for Ready { - type Output = T; - - #[inline] - fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { - Poll::Ready(self.0.take().unwrap()) - } -} - -/// Creates a future that is immediately ready with a success value. -pub(crate) fn ok(t: T) -> Ready> { - Ready(Some(Ok(t))) -} diff --git a/tokio/src/net/addr.rs b/tokio/src/net/addr.rs index ec4fa198ec1..13f743c9628 100644 --- a/tokio/src/net/addr.rs +++ b/tokio/src/net/addr.rs @@ -1,5 +1,4 @@ -use crate::future; - +use std::future; use std::io; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; @@ -56,7 +55,7 @@ impl sealed::ToSocketAddrsPriv for SocketAddr { fn to_socket_addrs(&self, _: sealed::Internal) -> Self::Future { let iter = Some(*self).into_iter(); - future::ok(iter) + future::ready(Ok(iter)) } } @@ -96,7 +95,7 @@ impl sealed::ToSocketAddrsPriv for (IpAddr, u16) { fn to_socket_addrs(&self, _: sealed::Internal) -> Self::Future { let iter = Some(SocketAddr::from(*self)).into_iter(); - future::ok(iter) + future::ready(Ok(iter)) } } @@ -138,7 +137,7 @@ impl sealed::ToSocketAddrsPriv for &[SocketAddr] { fn to_socket_addrs(&self, _: sealed::Internal) -> Self::Future { let iter = self.to_vec().into_iter(); - future::ok(iter) + future::ready(Ok(iter)) } }