Skip to content

Commit ee131aa

Browse files
Migrate to pin project lite (#595)
* REMOVE ME updates peak_wema test to pass * adds pin_project_lite dependency * uses pin_project_lite for load::Constant * uses pin_project_lite for load::PencingRequestsDiscover * uses pin_project_lite for load::PeakEwma * uses pin_project_lite for load::Completion * uses pin_project_lite for tests::support::IntoStream Turns IntoStream into a regular struct because pin_project_lite does not and will support tuple structs. https://github.com/taiki-e/pin-project-lite/blob/416be96f7777862c68b567c92a91887f69a8c2b3/src/lib.rs#L401-L408 * refactors opaque_future into a regular struct This enables migration to pin_project_lite, which does not and will not support tuple structs https://github.com/taiki-e/pin-project-lite/blob/416be96f7777862c68b567c92a91887f69a8c2b3/src/lib.rs#L401-L408 * migrates opaque_future to use pin_project_lite * removes tuple variant from load_shed::ResponseState enum * migrates load_shed::future to pin_project_lite * removes tuple variant from filter::future::State * migrates filter::future to pin_project_lite Note: the doc comment on AsyncResponseFuture::service was also reduced to a regular comment. This is a known limitation of pin_project_lite that the they have labeled as "help wanted". taiki-e/pin-project-lite#3 (comment) * migrates retry::Retry to pin_project_lite * refactors retry::future::State to enable pin_project_lite pin_project_lite has the current limitation of nto supporting doc comments taiki-e/pin-project-lite#3 (comment) pin_project_lite does not and will not support tuple variants https://github.com/taiki-e/pin-project-lite/blob/416be96f7777862c68b567c92a91887f69a8c2b3/src/lib.rs#L401-L408 * migrates retry::future to pin_project_lite * migrates spawn_ready::make to pin_project_lite * refactors buffer::future::ResponseState to allow pin_project_lite * migrates buffer::future to pin_project_lite * refactors util::AndThenFuture to allow pin_project_lite * migrates util::AndThenFuture to pin_project_lite * migrates hedge::Future to pin_project_lite * migrates hedge::select::ResponseFuture to pin_project_lite * refactors hedge::delay enum for pin_project_lite * refactors reconnect::future enum for pin_project_lite * refactors oneshot::State enum for pin_project_lite * migrates util::oneshot to pin_project_lite * migrates reconnect::future to pin_project_lite * migrates hedge::delay to pin_project_lite * migrates hedge::latency to pin_project_lite * migrates discover::list to pin_project_lite * migrates timeout::future to pin_project_lite * migrates balance::pool to pin_project_lite * migrates balance::p2c::make to pin_project_lite * migrates balance::p2c::service to pin_project_lite * migrates call_all::ordered to pin_project_lite * migrates call_all::common to pin_project_lite * migrates call_all::unordered to pin_project_lite * migrates util::optional::future to pin_project_lite * migrates limit::concurrency::future to pin_project_lite * migrates tower-balance example to pin_project_lite * applies cargo fmt * migrates tower-test to pin_project_lite * fixes cargo hack check peak_wma and pending_requests will now properly compile without the "discover" feature enabled. * fixes lint rename warning on nightly broken_intra_doc_links has been renamed to rustdoc::broken_intra_doc_links * migrates buffer::Worker to pin_project_lite pin_project_lite does support PinnedDrop https://github.com/taiki-e/pin-project-lite/pull/25/files However, it does not support generic trait bounds on the PinnedDrop impl. To workaround this, I removed the T::Error bound from the Worker struct definition, and moved `close_semaphore` to a a new impl without that trait bound. * fixes abort_on_drop test This test was also failing on master. * applies cargo fmt
1 parent 7776019 commit ee131aa

File tree

49 files changed

+668
-510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+668
-510
lines changed

tower-layer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
rust_2018_idioms,
66
unreachable_pub
77
)]
8-
#![deny(broken_intra_doc_links)]
8+
#![deny(rustdoc::broken_intra_doc_links)]
99

1010
//! Layer traits and extensions.
1111
//!

tower-service/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
rust_2018_idioms,
66
unreachable_pub
77
)]
8-
#![deny(broken_intra_doc_links)]
8+
#![deny(rustdoc::broken_intra_doc_links)]
99

1010
//! Definition of the core `Service` trait to Tower
1111
//!

tower-test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tokio = { version = "1.0", features = ["sync"] }
2727
tokio-test = "0.4"
2828
tower-layer = { version = "0.3", path = "../tower-layer" }
2929
tower-service = { version = "0.3" }
30-
pin-project = "1"
30+
pin-project-lite = "0.2"
3131

3232
[dev-dependencies]
3333
tokio = { version = "1.0", features = ["macros"] }

tower-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
unreachable_pub
77
)]
88
#![allow(elided_lifetimes_in_paths)]
9-
#![deny(broken_intra_doc_links)]
9+
#![deny(rustdoc::broken_intra_doc_links)]
1010

1111
//! Mock `Service` that can be used in tests.
1212

tower-test/src/mock/future.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::mock::error::{self, Error};
44
use futures_util::ready;
5-
use pin_project::pin_project;
5+
use pin_project_lite::pin_project;
66
use tokio::sync::oneshot;
77

88
use std::{
@@ -11,12 +11,13 @@ use std::{
1111
task::{Context, Poll},
1212
};
1313

14-
/// Future of the `Mock` response.
15-
#[pin_project]
16-
#[derive(Debug)]
17-
pub struct ResponseFuture<T> {
18-
#[pin]
19-
rx: Option<Rx<T>>,
14+
pin_project! {
15+
/// Future of the `Mock` response.
16+
#[derive(Debug)]
17+
pub struct ResponseFuture<T> {
18+
#[pin]
19+
rx: Option<Rx<T>>,
20+
}
2021
}
2122

2223
type Rx<T> = oneshot::Receiver<Result<T, Error>>;

tower/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ tokio = { version = "1", optional = true, features = ["sync"] }
7676
tokio-stream = { version = "0.1.0", optional = true }
7777
tokio-util = { version = "0.6.3", default-features = false, optional = true }
7878
tracing = { version = "0.1.2", optional = true }
79+
pin-project-lite = "0.2.7"
7980

8081
[dev-dependencies]
8182
futures = "0.3"

tower/examples/tower-balance.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use futures_core::{Stream, TryStream};
44
use futures_util::{stream, stream::StreamExt, stream::TryStreamExt};
55
use hdrhistogram::Histogram;
6-
use pin_project::pin_project;
6+
use pin_project_lite::pin_project;
77
use rand::{self, Rng};
88
use std::hash::Hash;
99
use std::time::Duration;
@@ -78,8 +78,17 @@ type Error = Box<dyn std::error::Error + Send + Sync>;
7878

7979
type Key = usize;
8080

81-
#[pin_project]
82-
struct Disco<S>(Vec<(Key, S)>);
81+
pin_project! {
82+
struct Disco<S> {
83+
services: Vec<(Key, S)>
84+
}
85+
}
86+
87+
impl<S> Disco<S> {
88+
fn new(services: Vec<(Key, S)>) -> Self {
89+
Self { services }
90+
}
91+
}
8392

8493
impl<S> Stream for Disco<S>
8594
where
@@ -88,7 +97,7 @@ where
8897
type Item = Result<Change<Key, S>, Error>;
8998

9099
fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> {
91-
match self.project().0.pop() {
100+
match self.project().services.pop() {
92101
Some((k, service)) => Poll::Ready(Some(Ok(Change::Insert(k, service)))),
93102
None => {
94103
// there may be more later
@@ -105,7 +114,7 @@ fn gen_disco() -> impl Discover<
105114
impl Service<Req, Response = Rsp, Error = Error, Future = impl Send> + Send,
106115
>,
107116
> + Send {
108-
Disco(
117+
Disco::new(
109118
MAX_ENDPOINT_LATENCIES
110119
.iter()
111120
.enumerate()

tower/src/balance/p2c/make.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::Balance;
22
use crate::discover::Discover;
33
use futures_core::ready;
4-
use pin_project::pin_project;
4+
use pin_project_lite::pin_project;
55
use std::hash::Hash;
66
use std::marker::PhantomData;
77
use std::{
@@ -29,15 +29,16 @@ pub struct MakeBalance<S, Req> {
2929
_marker: PhantomData<fn(Req)>,
3030
}
3131

32-
/// A [`Balance`] in the making.
33-
///
34-
/// [`Balance`]: crate::balance::p2c::Balance
35-
#[pin_project]
36-
#[derive(Debug)]
37-
pub struct MakeFuture<F, Req> {
38-
#[pin]
39-
inner: F,
40-
_marker: PhantomData<fn(Req)>,
32+
pin_project! {
33+
/// A [`Balance`] in the making.
34+
///
35+
/// [`Balance`]: crate::balance::p2c::Balance
36+
#[derive(Debug)]
37+
pub struct MakeFuture<F, Req> {
38+
#[pin]
39+
inner: F,
40+
_marker: PhantomData<fn(Req)>,
41+
}
4142
}
4243

4344
impl<S, Req> MakeBalance<S, Req> {

tower/src/balance/p2c/service.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::load::Load;
44
use crate::ready_cache::{error::Failed, ReadyCache};
55
use futures_core::ready;
66
use futures_util::future::{self, TryFutureExt};
7-
use pin_project::pin_project;
7+
use pin_project_lite::pin_project;
88
use rand::{rngs::SmallRng, Rng, SeedableRng};
99
use std::hash::Hash;
1010
use std::marker::PhantomData;
@@ -59,18 +59,19 @@ where
5959
}
6060
}
6161

62-
/// A Future that becomes satisfied when an `S`-typed service is ready.
63-
///
64-
/// May fail due to cancelation, i.e., if [`Discover`] removes the service from the service set.
65-
#[pin_project]
66-
#[derive(Debug)]
67-
struct UnreadyService<K, S, Req> {
68-
key: Option<K>,
69-
#[pin]
70-
cancel: oneshot::Receiver<()>,
71-
service: Option<S>,
72-
73-
_req: PhantomData<Req>,
62+
pin_project! {
63+
/// A Future that becomes satisfied when an `S`-typed service is ready.
64+
///
65+
/// May fail due to cancelation, i.e., if [`Discover`] removes the service from the service set.
66+
#[derive(Debug)]
67+
struct UnreadyService<K, S, Req> {
68+
key: Option<K>,
69+
#[pin]
70+
cancel: oneshot::Receiver<()>,
71+
service: Option<S>,
72+
73+
_req: PhantomData<Req>,
74+
}
7475
}
7576

7677
enum Error<E> {

tower/src/balance/pool/mod.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::discover::Change;
1919
use crate::load::Load;
2020
use crate::make::MakeService;
2121
use futures_core::{ready, Stream};
22-
use pin_project::pin_project;
22+
use pin_project_lite::pin_project;
2323
use slab::Slab;
2424
use std::{
2525
fmt,
@@ -42,23 +42,24 @@ enum Level {
4242
High,
4343
}
4444

45-
/// A wrapper around `MakeService` that discovers a new service when load is high, and removes a
46-
/// service when load is low. See [`Pool`].
47-
#[pin_project]
48-
pub struct PoolDiscoverer<MS, Target, Request>
49-
where
50-
MS: MakeService<Target, Request>,
51-
{
52-
maker: MS,
53-
#[pin]
54-
making: Option<MS::Future>,
55-
target: Target,
56-
load: Level,
57-
services: Slab<()>,
58-
died_tx: tokio::sync::mpsc::UnboundedSender<usize>,
59-
#[pin]
60-
died_rx: tokio::sync::mpsc::UnboundedReceiver<usize>,
61-
limit: Option<usize>,
45+
pin_project! {
46+
/// A wrapper around `MakeService` that discovers a new service when load is high, and removes a
47+
/// service when load is low. See [`Pool`].
48+
pub struct PoolDiscoverer<MS, Target, Request>
49+
where
50+
MS: MakeService<Target, Request>,
51+
{
52+
maker: MS,
53+
#[pin]
54+
making: Option<MS::Future>,
55+
target: Target,
56+
load: Level,
57+
services: Slab<()>,
58+
died_tx: tokio::sync::mpsc::UnboundedSender<usize>,
59+
#[pin]
60+
died_rx: tokio::sync::mpsc::UnboundedReceiver<usize>,
61+
limit: Option<usize>,
62+
}
6263
}
6364

6465
impl<MS, Target, Request> fmt::Debug for PoolDiscoverer<MS, Target, Request>

0 commit comments

Comments
 (0)