Skip to content

Commit

Permalink
chore: Replace type related to future with standard library
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Dec 19, 2024
1 parent 7dc533e commit e80f387
Show file tree
Hide file tree
Showing 43 changed files with 107 additions and 129 deletions.
1 change: 0 additions & 1 deletion tower-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ categories = ["asynchronous", "network-programming"]
edition = "2018"

[dependencies]
futures-util = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
tokio-test = { workspace = true }
tower-layer = { version = "0.3", path = "../tower-layer" }
Expand Down
3 changes: 1 addition & 2 deletions tower-test/src/mock/future.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//! Future types
use crate::mock::error::{self, Error};
use futures_util::ready;
use pin_project_lite::pin_project;
use tokio::sync::oneshot;

use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};

pin_project! {
Expand Down
24 changes: 10 additions & 14 deletions tower/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ edition = "2018"
rust-version = "1.64.0"

[features]

# Internal
__common = ["futures-core", "pin-project-lite"]

full = [
"balance",
"buffer",
Expand All @@ -45,21 +41,21 @@ full = [
# FIXME: Use weak dependency once available (https://github.com/rust-lang/cargo/issues/8832)
log = ["tracing/log"]
balance = ["discover", "load", "ready-cache", "make", "slab", "util"]
buffer = ["__common", "tokio/sync", "tokio/rt", "tokio-util", "tracing"]
discover = ["__common"]
filter = ["__common", "futures-util"]
buffer = ["tokio/sync", "tokio/rt", "tokio-util", "tracing", "pin-project-lite"]
discover = ["futures-core", "pin-project-lite"]
filter = ["futures-util", "pin-project-lite"]
hedge = ["util", "filter", "futures-util", "hdrhistogram", "tokio/time", "tracing"]
limit = ["__common", "tokio/time", "tokio/sync", "tokio-util", "tracing"]
load = ["__common", "tokio/time", "tracing"]
load-shed = ["__common"]
make = ["futures-util", "pin-project-lite", "tokio/io-std"]
limit = ["tokio/time", "tokio/sync", "tokio-util", "tracing", "pin-project-lite"]
load = ["tokio/time", "tracing", "pin-project-lite"]
load-shed = ["pin-project-lite"]
make = ["pin-project-lite", "tokio/io-std"]
ready-cache = ["futures-core", "futures-util", "indexmap", "tokio/sync", "tracing", "pin-project-lite"]
reconnect = ["make", "tokio/io-std", "tracing"]
retry = ["__common", "tokio/time", "util"]
spawn-ready = ["__common", "futures-util", "tokio/sync", "tokio/rt", "util", "tracing"]
retry = ["tokio/time", "util"]
spawn-ready = ["futures-util", "tokio/sync", "tokio/rt", "util", "tracing"]
steer = []
timeout = ["pin-project-lite", "tokio/time"]
util = ["__common", "futures-util", "pin-project-lite", "sync_wrapper"]
util = ["futures-core", "futures-util", "pin-project-lite", "sync_wrapper"]

[dependencies]
tower-layer = { version = "0.3.3", path = "../tower-layer" }
Expand Down
3 changes: 1 addition & 2 deletions tower/src/balance/p2c/make.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use super::Balance;
use crate::discover::Discover;
use futures_core::ready;
use pin_project_lite::pin_project;
use std::hash::Hash;
use std::marker::PhantomData;
use std::{
fmt,
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tower_service::Service;

Expand Down
3 changes: 1 addition & 2 deletions tower/src/balance/p2c/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use crate::discover::{Change, Discover};
use crate::load::Load;
use crate::ready_cache::{error::Failed, ReadyCache};
use crate::util::rng::{sample_floyd2, HasherRng, Rng};
use futures_core::ready;
use futures_util::future::{self, TryFutureExt};
use std::hash::Hash;
use std::marker::PhantomData;
use std::{
fmt,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tower_service::Service;
use tracing::{debug, trace};
Expand Down
3 changes: 1 addition & 2 deletions tower/src/buffer/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
//! [`Buffer`]: crate::buffer::Buffer
use super::{error::Closed, message};
use futures_core::ready;
use pin_project_lite::pin_project;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};

pin_project! {
Expand Down
3 changes: 1 addition & 2 deletions tower/src/buffer/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use super::{
error::{Closed, ServiceError},
message::Message,
};
use futures_core::ready;
use std::sync::{Arc, Mutex};
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tokio::sync::mpsc;
use tower_service::Service;
Expand Down
2 changes: 1 addition & 1 deletion tower/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl<L> ServiceBuilder<L> {
/// impl Service<Request> for MyService {
/// type Response = Response;
/// type Error = Error;
/// type Future = futures_util::future::Ready<Result<Response, Error>>;
/// type Future = std::future::Ready<Result<Response, Error>>;
///
/// fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
/// // ...
Expand Down
3 changes: 2 additions & 1 deletion tower/src/discover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
//! # Examples
//!
//! ```rust
//! use futures_util::{future::poll_fn, pin_mut};
//! use std::future::poll_fn;
//! use futures_util::pin_mut;
//! use tower::discover::{Change, Discover};
//! async fn services_monitor<D: Discover>(services: D) {
//! pin_mut!(services);
Expand Down
5 changes: 2 additions & 3 deletions tower/src/filter/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
use super::AsyncPredicate;
use crate::BoxError;
use futures_core::ready;
use pin_project_lite::pin_project;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tower_service::Service;

Expand Down Expand Up @@ -35,7 +34,7 @@ opaque_future! {
/// [`Filter`]: crate::filter::Filter
pub type ResponseFuture<R, F> =
futures_util::future::Either<
futures_util::future::Ready<Result<R, crate::BoxError>>,
std::future::Ready<Result<R, crate::BoxError>>,
futures_util::future::ErrInto<F, crate::BoxError>
>;
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
fn call(&mut self, request: Request) -> Self::Future {
ResponseFuture::new(match self.predicate.check(request) {
Ok(request) => Either::Right(self.inner.call(request).err_into()),
Err(e) => Either::Left(futures_util::future::ready(Err(e))),
Err(e) => Either::Left(std::future::ready(Err(e))),
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions tower/src/hedge/delay.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use futures_util::ready;
use pin_project_lite::pin_project;
use std::time::Duration;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tower_service::Service;

Expand Down
3 changes: 1 addition & 2 deletions tower/src/hedge/latency.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use futures_util::ready;
use pin_project_lite::pin_project;
use std::time::Duration;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tokio::time::Instant;
use tower_service::Service;
Expand Down
9 changes: 5 additions & 4 deletions tower/src/hedge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#![warn(missing_debug_implementations, missing_docs, unreachable_pub)]

use crate::filter::AsyncFilter;
use futures_util::future;
use futures_util::future::Either;
use pin_project_lite::pin_project;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::{
future,
pin::Pin,
task::{Context, Poll},
};
Expand Down Expand Up @@ -222,21 +223,21 @@ impl<P, Request> crate::filter::AsyncPredicate<Request> for PolicyPredicate<P>
where
P: Policy<Request>,
{
type Future = future::Either<
type Future = Either<
future::Ready<Result<Request, crate::BoxError>>,
future::Pending<Result<Request, crate::BoxError>>,
>;
type Request = Request;

fn check(&mut self, request: Request) -> Self::Future {
if self.0.can_retry(&request) {
future::Either::Left(future::ready(Ok(request)))
Either::Left(future::ready(Ok(request)))
} else {
// If the hedge retry should not be issued, we simply want to wait
// for the result of the original request. Therefore we don't want
// to return an error here. Instead, we use future::pending to ensure
// that the original request wins the select.
future::Either::Right(future::pending())
Either::Right(future::pending())
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions tower/src/limit/concurrency/future.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! [`Future`] types
//!
//! [`Future`]: std::future::Future
use futures_core::ready;
use pin_project_lite::pin_project;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tokio::sync::OwnedSemaphorePermit;

Expand Down
3 changes: 1 addition & 2 deletions tower/src/limit/concurrency/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use tokio::sync::{OwnedSemaphorePermit, Semaphore};
use tokio_util::sync::PollSemaphore;
use tower_service::Service;

use futures_core::ready;
use std::{
sync::Arc,
task::{Context, Poll},
task::{ready, Context, Poll},
};

/// Enforces a limit on the concurrent number of requests the underlying
Expand Down
3 changes: 1 addition & 2 deletions tower/src/limit/rate/service.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use super::Rate;
use futures_core::ready;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};
use tokio::time::{Instant, Sleep};
use tower_service::Service;
Expand Down
3 changes: 1 addition & 2 deletions tower/src/load/completion.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Application-specific request completion semantics.
use futures_core::ready;
use pin_project_lite::pin_project;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};

/// Attaches `H`-typed completion tracker to `V` typed values.
Expand Down
4 changes: 2 additions & 2 deletions tower/src/load/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#[cfg(feature = "discover")]
use crate::discover::{Change, Discover};
#[cfg(feature = "discover")]
use futures_core::{ready, Stream};
use futures_core::Stream;
#[cfg(feature = "discover")]
use std::pin::Pin;
use std::{pin::Pin, task::ready};

use super::Load;
use pin_project_lite::pin_project;
Expand Down
9 changes: 4 additions & 5 deletions tower/src/load/peak_ewma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#[cfg(feature = "discover")]
use crate::discover::{Change, Discover};
#[cfg(feature = "discover")]
use futures_core::{ready, Stream};
use futures_core::Stream;
#[cfg(feature = "discover")]
use pin_project_lite::pin_project;
#[cfg(feature = "discover")]
use std::pin::Pin;
use std::{pin::Pin, task::ready};

use super::completion::{CompleteOnResponse, TrackCompletion, TrackCompletionFuture};
use super::Load;
Expand Down Expand Up @@ -309,8 +309,7 @@ fn nanos(d: Duration) -> f64 {

#[cfg(test)]
mod tests {
use futures_util::future;
use std::time::Duration;
use std::{future, time::Duration};
use tokio::time;
use tokio_test::{assert_ready, assert_ready_ok, task};

Expand All @@ -327,7 +326,7 @@ mod tests {
}

fn call(&mut self, (): ()) -> Self::Future {
future::ok(())
future::ready(Ok(()))
}
}

Expand Down
12 changes: 7 additions & 5 deletions tower/src/load/pending_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#[cfg(feature = "discover")]
use crate::discover::{Change, Discover};
#[cfg(feature = "discover")]
use futures_core::{ready, Stream};
use futures_core::Stream;
#[cfg(feature = "discover")]
use pin_project_lite::pin_project;
#[cfg(feature = "discover")]
use std::pin::Pin;
use std::{pin::Pin, task::ready};

use super::completion::{CompleteOnResponse, TrackCompletion, TrackCompletionFuture};
use super::Load;
Expand Down Expand Up @@ -148,8 +148,10 @@ impl RefCount {
#[cfg(test)]
mod tests {
use super::*;
use futures_util::future;
use std::task::{Context, Poll};
use std::{
future,
task::{Context, Poll},
};

struct Svc;
impl Service<()> for Svc {
Expand All @@ -162,7 +164,7 @@ mod tests {
}

fn call(&mut self, (): ()) -> Self::Future {
future::ok(())
future::ready(Ok(()))
}
}

Expand Down
3 changes: 1 addition & 2 deletions tower/src/load_shed/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use std::fmt;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};

use futures_core::ready;
use pin_project_lite::pin_project;

use super::error::Overloaded;
Expand Down
Loading

0 comments on commit e80f387

Please sign in to comment.