From 3f31ffd2cf15f1e905142e5f43ab39ac995c22ed Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 25 Sep 2022 16:03:54 +0200 Subject: [PATCH 1/2] chore: Use doc_auto_cfg (#693) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … so extra doc(cfg) attributes aren't needed in most places. --- tower/src/builder/mod.rs | 19 ------------------- tower/src/lib.rs | 20 +------------------- tower/src/limit/concurrency/service.rs | 1 - tower/src/limit/rate/service.rs | 1 - tower/src/load/constant.rs | 1 - tower/src/load/peak_ewma.rs | 1 - tower/src/util/mod.rs | 2 -- 7 files changed, 1 insertion(+), 44 deletions(-) diff --git a/tower/src/builder/mod.rs b/tower/src/builder/mod.rs index 33684137d..cfea50dfc 100644 --- a/tower/src/builder/mod.rs +++ b/tower/src/builder/mod.rs @@ -152,7 +152,6 @@ impl ServiceBuilder { /// # } /// ``` #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn option_layer( self, layer: Option, @@ -176,7 +175,6 @@ impl ServiceBuilder { /// /// [`Buffer`]: crate::buffer #[cfg(feature = "buffer")] - #[cfg_attr(docsrs, doc(cfg(feature = "buffer")))] pub fn buffer( self, bound: usize, @@ -195,7 +193,6 @@ impl ServiceBuilder { /// /// [`ConcurrencyLimit`]: crate::limit::concurrency #[cfg(feature = "limit")] - #[cfg_attr(docsrs, doc(cfg(feature = "limit")))] pub fn concurrency_limit( self, max: usize, @@ -219,7 +216,6 @@ impl ServiceBuilder { /// [`poll_ready`]: crate::Service::poll_ready /// [`Pending`]: std::task::Poll::Pending #[cfg(feature = "load-shed")] - #[cfg_attr(docsrs, doc(cfg(feature = "load-shed")))] pub fn load_shed(self) -> ServiceBuilder> { self.layer(crate::load_shed::LoadShedLayer::new()) } @@ -231,7 +227,6 @@ impl ServiceBuilder { /// /// [`RateLimit`]: crate::limit::rate #[cfg(feature = "limit")] - #[cfg_attr(docsrs, doc(cfg(feature = "limit")))] pub fn rate_limit( self, num: u64, @@ -251,7 +246,6 @@ impl ServiceBuilder { /// [`Retry`]: crate::retry /// [policy]: crate::retry::Policy #[cfg(feature = "retry")] - #[cfg_attr(docsrs, doc(cfg(feature = "retry")))] pub fn retry

(self, policy: P) -> ServiceBuilder, L>> { self.layer(crate::retry::RetryLayer::new(policy)) } @@ -266,7 +260,6 @@ impl ServiceBuilder { /// /// [`timeout`]: crate::timeout #[cfg(feature = "timeout")] - #[cfg_attr(docsrs, doc(cfg(feature = "timeout")))] pub fn timeout( self, timeout: std::time::Duration, @@ -284,7 +277,6 @@ impl ServiceBuilder { /// [`Filter`]: crate::filter /// [`Predicate`]: crate::filter::Predicate #[cfg(feature = "filter")] - #[cfg_attr(docsrs, doc(cfg(feature = "filter")))] pub fn filter

( self, predicate: P, @@ -302,7 +294,6 @@ impl ServiceBuilder { /// [`AsyncFilter`]: crate::filter::AsyncFilter /// [`AsyncPredicate`]: crate::filter::AsyncPredicate #[cfg(feature = "filter")] - #[cfg_attr(docsrs, doc(cfg(feature = "filter")))] pub fn filter_async

( self, predicate: P, @@ -371,7 +362,6 @@ impl ServiceBuilder { /// /// [`MapRequest`]: crate::util::MapRequest #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn map_request( self, f: F, @@ -392,7 +382,6 @@ impl ServiceBuilder { /// [`MapResponse`]: crate::util::MapResponse /// [`map_response` combinator]: crate::util::ServiceExt::map_response #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn map_response( self, f: F, @@ -410,7 +399,6 @@ impl ServiceBuilder { /// [`MapErr`]: crate::util::MapErr /// [`map_err` combinator]: crate::util::ServiceExt::map_err #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn map_err(self, f: F) -> ServiceBuilder, L>> { self.layer(crate::util::MapErrLayer::new(f)) } @@ -424,7 +412,6 @@ impl ServiceBuilder { /// [`MapFutureLayer`]: crate::util::MapFutureLayer /// [`map_future`]: crate::util::ServiceExt::map_future #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn map_future(self, f: F) -> ServiceBuilder, L>> { self.layer(crate::util::MapFutureLayer::new(f)) } @@ -448,7 +435,6 @@ impl ServiceBuilder { /// [`map_response`]: ServiceBuilder::map_response /// [`map_err`]: ServiceBuilder::map_err #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn then(self, f: F) -> ServiceBuilder, L>> { self.layer(crate::util::ThenLayer::new(f)) } @@ -470,7 +456,6 @@ impl ServiceBuilder { /// [`and_then` combinator]: crate::util::ServiceExt::and_then /// [`AndThen`]: crate::util::AndThen #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn and_then(self, f: F) -> ServiceBuilder, L>> { self.layer(crate::util::AndThenLayer::new(f)) } @@ -487,7 +472,6 @@ impl ServiceBuilder { /// [`map_result` combinator]: crate::util::ServiceExt::map_result /// [`MapResult`]: crate::util::MapResult #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn map_result(self, f: F) -> ServiceBuilder, L>> { self.layer(crate::util::MapResultLayer::new(f)) } @@ -553,7 +537,6 @@ impl ServiceBuilder { /// [`Service`]: crate::Service /// [`service_fn`]: crate::service_fn #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn service_fn(self, f: F) -> L::Service where L: Layer>, @@ -720,7 +703,6 @@ impl ServiceBuilder { /// /// [`BoxService::layer()`]: crate::util::BoxService::layer() #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn boxed( self, ) -> ServiceBuilder< @@ -784,7 +766,6 @@ impl ServiceBuilder { /// [`BoxCloneService`]: crate::util::BoxCloneService /// [`boxed`]: Self::boxed #[cfg(feature = "util")] - #[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub fn boxed_clone( self, ) -> ServiceBuilder< diff --git a/tower/src/lib.rs b/tower/src/lib.rs index afa260e9c..073fd016f 100644 --- a/tower/src/lib.rs +++ b/tower/src/lib.rs @@ -7,7 +7,7 @@ #![forbid(unsafe_code)] #![allow(elided_lifetimes_in_paths, clippy::type_complexity)] #![cfg_attr(test, allow(clippy::float_cmp))] -#![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))] // `rustdoc::broken_intra_doc_links` is checked on CI //! `async fn(Request) -> Result` @@ -164,67 +164,49 @@ #[macro_use] pub(crate) mod macros; #[cfg(feature = "balance")] -#[cfg_attr(docsrs, doc(cfg(feature = "balance")))] pub mod balance; #[cfg(feature = "buffer")] -#[cfg_attr(docsrs, doc(cfg(feature = "buffer")))] pub mod buffer; #[cfg(feature = "discover")] -#[cfg_attr(docsrs, doc(cfg(feature = "discover")))] pub mod discover; #[cfg(feature = "filter")] -#[cfg_attr(docsrs, doc(cfg(feature = "filter")))] pub mod filter; #[cfg(feature = "hedge")] -#[cfg_attr(docsrs, doc(cfg(feature = "hedge")))] pub mod hedge; #[cfg(feature = "limit")] -#[cfg_attr(docsrs, doc(cfg(feature = "limit")))] pub mod limit; #[cfg(feature = "load")] -#[cfg_attr(docsrs, doc(cfg(feature = "load")))] pub mod load; #[cfg(feature = "load-shed")] -#[cfg_attr(docsrs, doc(cfg(feature = "load-shed")))] pub mod load_shed; #[cfg(feature = "make")] -#[cfg_attr(docsrs, doc(cfg(feature = "make")))] pub mod make; #[cfg(feature = "ready-cache")] -#[cfg_attr(docsrs, doc(cfg(feature = "ready-cache")))] pub mod ready_cache; #[cfg(feature = "reconnect")] -#[cfg_attr(docsrs, doc(cfg(feature = "reconnect")))] pub mod reconnect; #[cfg(feature = "retry")] -#[cfg_attr(docsrs, doc(cfg(feature = "retry")))] pub mod retry; #[cfg(feature = "spawn-ready")] -#[cfg_attr(docsrs, doc(cfg(feature = "spawn-ready")))] pub mod spawn_ready; #[cfg(feature = "steer")] -#[cfg_attr(docsrs, doc(cfg(feature = "steer")))] pub mod steer; #[cfg(feature = "timeout")] -#[cfg_attr(docsrs, doc(cfg(feature = "timeout")))] pub mod timeout; #[cfg(feature = "util")] -#[cfg_attr(docsrs, doc(cfg(feature = "util")))] pub mod util; pub mod builder; pub mod layer; #[cfg(feature = "util")] -#[cfg_attr(docsrs, doc(cfg(feature = "util")))] #[doc(inline)] pub use self::util::{service_fn, ServiceExt}; #[doc(inline)] pub use crate::builder::ServiceBuilder; #[cfg(feature = "make")] -#[cfg_attr(docsrs, doc(cfg(feature = "make")))] #[doc(inline)] pub use crate::make::MakeService; #[doc(inline)] diff --git a/tower/src/limit/concurrency/service.rs b/tower/src/limit/concurrency/service.rs index 02d85345f..bb9cf5eeb 100644 --- a/tower/src/limit/concurrency/service.rs +++ b/tower/src/limit/concurrency/service.rs @@ -107,7 +107,6 @@ impl Clone for ConcurrencyLimit { } #[cfg(feature = "load")] -#[cfg_attr(docsrs, doc(cfg(feature = "load")))] impl crate::load::Load for ConcurrencyLimit where S: crate::load::Load, diff --git a/tower/src/limit/rate/service.rs b/tower/src/limit/rate/service.rs index b7604603b..0aa1d694b 100644 --- a/tower/src/limit/rate/service.rs +++ b/tower/src/limit/rate/service.rs @@ -119,7 +119,6 @@ where } #[cfg(feature = "load")] -#[cfg_attr(docsrs, doc(cfg(feature = "load")))] impl crate::load::Load for RateLimit where S: crate::load::Load, diff --git a/tower/src/load/constant.rs b/tower/src/load/constant.rs index a7c874e2b..f05182f85 100644 --- a/tower/src/load/constant.rs +++ b/tower/src/load/constant.rs @@ -60,7 +60,6 @@ where /// Proxies [`Discover`] such that all changes are wrapped with a constant load. #[cfg(feature = "discover")] -#[cfg_attr(docsrs, doc(cfg(feature = "discover")))] impl Stream for Constant { type Item = Result>, D::Error>; diff --git a/tower/src/load/peak_ewma.rs b/tower/src/load/peak_ewma.rs index 61ac2011f..c145ab60c 100644 --- a/tower/src/load/peak_ewma.rs +++ b/tower/src/load/peak_ewma.rs @@ -186,7 +186,6 @@ impl PeakEwmaDiscover { } #[cfg(feature = "discover")] -#[cfg_attr(docsrs, doc(cfg(feature = "discover")))] impl Stream for PeakEwmaDiscover where D: Discover, diff --git a/tower/src/util/mod.rs b/tower/src/util/mod.rs index 71253e99d..7cdfc5aa2 100644 --- a/tower/src/util/mod.rs +++ b/tower/src/util/mod.rs @@ -664,7 +664,6 @@ pub trait ServiceExt: tower_service::Service { /// [`Filter`]: crate::filter::Filter /// [predicate]: crate::filter::Predicate #[cfg(feature = "filter")] - #[cfg_attr(docsrs, doc(cfg(feature = "filter")))] fn filter(self, filter: F) -> crate::filter::Filter where Self: Sized, @@ -751,7 +750,6 @@ pub trait ServiceExt: tower_service::Service { /// [`AsyncFilter`]: crate::filter::AsyncFilter /// [asynchronous predicate]: crate::filter::AsyncPredicate #[cfg(feature = "filter")] - #[cfg_attr(docsrs, doc(cfg(feature = "filter")))] fn filter_async(self, filter: F) -> crate::filter::AsyncFilter where Self: Sized, From 87fa8ef78257ebeb04a3cb0582e8c5edd43a49a7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 4 Oct 2022 20:54:39 +0200 Subject: [PATCH 2/2] layer: Implement Layer for tuples of up to 16 elements (#694) --- tower-layer/src/lib.rs | 1 + tower-layer/src/tuple.rs | 330 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 331 insertions(+) create mode 100644 tower-layer/src/tuple.rs diff --git a/tower-layer/src/lib.rs b/tower-layer/src/lib.rs index d1694adf3..4823fcc16 100644 --- a/tower-layer/src/lib.rs +++ b/tower-layer/src/lib.rs @@ -19,6 +19,7 @@ mod identity; mod layer_fn; mod stack; +mod tuple; pub use self::{ identity::Identity, diff --git a/tower-layer/src/tuple.rs b/tower-layer/src/tuple.rs new file mode 100644 index 000000000..14b973abe --- /dev/null +++ b/tower-layer/src/tuple.rs @@ -0,0 +1,330 @@ +use crate::Layer; + +impl Layer for () { + type Service = S; + + fn layer(&self, service: S) -> Self::Service { + service + } +} + +impl Layer for (L1,) +where + L1: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1,) = self; + l1.layer(service) + } +} + +impl Layer for (L1, L2) +where + L1: Layer, + L2: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2) = self; + l1.layer(l2.layer(service)) + } +} + +impl Layer for (L1, L2, L3) +where + L1: Layer, + L2: Layer, + L3: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3) = self; + l1.layer((l2, l3).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4) = self; + l1.layer((l2, l3, l4).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5) = self; + l1.layer((l2, l3, l4, l5).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5, L6) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6) = self; + l1.layer((l2, l3, l4, l5, l6).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5, L6, L7) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7) = self; + l1.layer((l2, l3, l4, l5, l6, l7).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5, L6, L7, L8) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8).layer(service)) + } +} + +impl Layer for (L1, L2, L3, L4, L5, L6, L7, L8, L9) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, + L13: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13).layer(service)) + } +} + +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, + L13: Layer, + L14: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14).layer(service)) + } +} + +#[rustfmt::skip] +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, + L13: Layer, + L14: Layer, + L15: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15).layer(service)) + } +} + +#[rustfmt::skip] +impl Layer + for (L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16) +where + L1: Layer, + L2: Layer, + L3: Layer, + L4: Layer, + L5: Layer, + L6: Layer, + L7: Layer, + L8: Layer, + L9: Layer, + L10: Layer, + L11: Layer, + L12: Layer, + L13: Layer, + L14: Layer, + L15: Layer, + L16: Layer, +{ + type Service = L1::Service; + + fn layer(&self, service: S) -> Self::Service { + let (l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16) = self; + l1.layer((l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16).layer(service)) + } +}