diff --git a/tower-layer/src/identity.rs b/tower-layer/src/identity.rs index 5ce805bd1..5233a1d81 100644 --- a/tower-layer/src/identity.rs +++ b/tower-layer/src/identity.rs @@ -14,7 +14,7 @@ pub struct Identity { impl Identity { /// Create a new [`Identity`] value - pub fn new() -> Identity { + pub const fn new() -> Identity { Identity { _p: () } } } diff --git a/tower-layer/src/stack.rs b/tower-layer/src/stack.rs index cc0b826e9..cb6bac7b7 100644 --- a/tower-layer/src/stack.rs +++ b/tower-layer/src/stack.rs @@ -10,7 +10,7 @@ pub struct Stack { impl Stack { /// Create a new `Stack`. - pub fn new(inner: Inner, outer: Outer) -> Self { + pub const fn new(inner: Inner, outer: Outer) -> Self { Stack { inner, outer } } } diff --git a/tower-service/src/lib.rs b/tower-service/src/lib.rs index d3ddd20f4..58cc2eb1c 100644 --- a/tower-service/src/lib.rs +++ b/tower-service/src/lib.rs @@ -130,7 +130,7 @@ use std::task::{Context, Poll}; /// } /// /// impl Timeout { -/// pub fn new(inner: T, timeout: Duration) -> Timeout { +/// pub const fn new(inner: T, timeout: Duration) -> Timeout { /// Timeout { /// inner, /// timeout @@ -204,7 +204,7 @@ use std::task::{Context, Poll}; /// pub struct TimeoutLayer(Duration); /// /// impl TimeoutLayer { -/// pub fn new(delay: Duration) -> Self { +/// pub const fn new(delay: Duration) -> Self { /// TimeoutLayer(delay) /// } /// } diff --git a/tower/src/balance/p2c/layer.rs b/tower/src/balance/p2c/layer.rs index ce59c6e06..6a2032c04 100644 --- a/tower/src/balance/p2c/layer.rs +++ b/tower/src/balance/p2c/layer.rs @@ -24,7 +24,7 @@ pub struct MakeBalanceLayer { impl MakeBalanceLayer { /// Build balancers using operating system entropy. - pub fn new() -> Self { + pub const fn new() -> Self { Self { _marker: PhantomData, } diff --git a/tower/src/balance/p2c/make.rs b/tower/src/balance/p2c/make.rs index 538d70360..45a35d1b4 100644 --- a/tower/src/balance/p2c/make.rs +++ b/tower/src/balance/p2c/make.rs @@ -42,7 +42,7 @@ pin_project! { impl MakeBalance { /// Build balancers using operating system entropy. - pub fn new(make_discover: S) -> Self { + pub const fn new(make_discover: S) -> Self { Self { inner: make_discover, _marker: PhantomData, diff --git a/tower/src/buffer/layer.rs b/tower/src/buffer/layer.rs index 8ef916714..3fc26ab59 100644 --- a/tower/src/buffer/layer.rs +++ b/tower/src/buffer/layer.rs @@ -33,7 +33,7 @@ impl BufferLayer { /// [`Poll::Ready`]: std::task::Poll::Ready /// [`call`]: crate::Service::call /// [`poll_ready`]: crate::Service::poll_ready - pub fn new(bound: usize) -> Self { + pub const fn new(bound: usize) -> Self { BufferLayer { bound, _p: PhantomData, diff --git a/tower/src/filter/layer.rs b/tower/src/filter/layer.rs index 4ca634449..30cbcdeca 100644 --- a/tower/src/filter/layer.rs +++ b/tower/src/filter/layer.rs @@ -35,7 +35,7 @@ impl FilterLayer { /// /// [`Predicate`]: crate::filter::Predicate /// [`Filter`]: crate::filter::Filter - pub fn new(predicate: U) -> Self { + pub const fn new(predicate: U) -> Self { Self { predicate } } } @@ -57,7 +57,7 @@ impl AsyncFilterLayer { /// /// [`AsyncPredicate`]: crate::filter::AsyncPredicate /// [`Filter`]: crate::filter::Filter - pub fn new(predicate: U) -> Self { + pub const fn new(predicate: U) -> Self { Self { predicate } } } diff --git a/tower/src/filter/mod.rs b/tower/src/filter/mod.rs index b7c05cf6a..c53ba404f 100644 --- a/tower/src/filter/mod.rs +++ b/tower/src/filter/mod.rs @@ -61,7 +61,7 @@ pub struct AsyncFilter { impl Filter { /// Returns a new [`Filter`] service wrapping `inner`. - pub fn new(inner: T, predicate: U) -> Self { + pub const fn new(inner: T, predicate: U) -> Self { Self { inner, predicate } } @@ -123,7 +123,7 @@ where impl AsyncFilter { /// Returns a new [`AsyncFilter`] service wrapping `inner`. - pub fn new(inner: T, predicate: U) -> Self { + pub const fn new(inner: T, predicate: U) -> Self { Self { inner, predicate } } diff --git a/tower/src/hedge/delay.rs b/tower/src/hedge/delay.rs index 3d634bfaa..7b45c0eff 100644 --- a/tower/src/hedge/delay.rs +++ b/tower/src/hedge/delay.rs @@ -62,7 +62,7 @@ impl State { } impl Delay { - pub fn new(policy: P, service: S) -> Self + pub const fn new(policy: P, service: S) -> Self where P: Policy, S: Service + Clone, diff --git a/tower/src/hedge/latency.rs b/tower/src/hedge/latency.rs index b1a8b2459..723652aaa 100644 --- a/tower/src/hedge/latency.rs +++ b/tower/src/hedge/latency.rs @@ -38,7 +38,7 @@ impl Latency where R: Record + Clone, { - pub fn new(rec: R, service: S) -> Self + pub const fn new(rec: R, service: S) -> Self where S: Service, S::Error: Into, diff --git a/tower/src/hedge/select.rs b/tower/src/hedge/select.rs index 5d1573c08..e9f2660d5 100644 --- a/tower/src/hedge/select.rs +++ b/tower/src/hedge/select.rs @@ -34,7 +34,7 @@ pin_project! { } impl Select { - pub fn new(policy: P, a: A, b: B) -> Self + pub const fn new(policy: P, a: A, b: B) -> Self where P: Policy, A: Service, diff --git a/tower/src/limit/concurrency/layer.rs b/tower/src/limit/concurrency/layer.rs index 1966d5785..30257c457 100644 --- a/tower/src/limit/concurrency/layer.rs +++ b/tower/src/limit/concurrency/layer.rs @@ -13,7 +13,7 @@ pub struct ConcurrencyLimitLayer { impl ConcurrencyLimitLayer { /// Create a new concurrency limit layer. - pub fn new(max: usize) -> Self { + pub const fn new(max: usize) -> Self { ConcurrencyLimitLayer { max } } } diff --git a/tower/src/limit/rate/layer.rs b/tower/src/limit/rate/layer.rs index 9051ddd08..5f8d31aaf 100644 --- a/tower/src/limit/rate/layer.rs +++ b/tower/src/limit/rate/layer.rs @@ -11,7 +11,7 @@ pub struct RateLimitLayer { impl RateLimitLayer { /// Create new rate limit layer. - pub fn new(num: u64, per: Duration) -> Self { + pub const fn new(num: u64, per: Duration) -> Self { let rate = Rate::new(num, per); RateLimitLayer { rate } } diff --git a/tower/src/limit/rate/rate.rs b/tower/src/limit/rate/rate.rs index d0736f427..6c54c14fc 100644 --- a/tower/src/limit/rate/rate.rs +++ b/tower/src/limit/rate/rate.rs @@ -13,9 +13,9 @@ impl Rate { /// # Panics /// /// This function panics if `num` or `per` is 0. - pub fn new(num: u64, per: Duration) -> Self { + pub const fn new(num: u64, per: Duration) -> Self { assert!(num > 0); - assert!(per > Duration::from_millis(0)); + assert!(!per.is_zero()); Rate { num, per } } diff --git a/tower/src/load/completion.rs b/tower/src/load/completion.rs index 3c14a7ff7..857e05536 100644 --- a/tower/src/load/completion.rs +++ b/tower/src/load/completion.rs @@ -59,7 +59,7 @@ pin_project! { impl TrackCompletionFuture { /// Wraps a future, propagating the tracker into its value if successful. - pub fn new(completion: C, handle: H, future: F) -> Self { + pub const fn new(completion: C, handle: H, future: F) -> Self { TrackCompletionFuture { future, completion, diff --git a/tower/src/load/constant.rs b/tower/src/load/constant.rs index f05182f85..b53a10bf5 100644 --- a/tower/src/load/constant.rs +++ b/tower/src/load/constant.rs @@ -27,7 +27,7 @@ pin_project! { impl Constant { /// Wraps a `T`-typed service with a constant `M`-typed load metric. - pub fn new(inner: T, load: M) -> Self { + pub const fn new(inner: T, load: M) -> Self { Self { inner, load } } } diff --git a/tower/src/load/pending_requests.rs b/tower/src/load/pending_requests.rs index 3d8689bbe..2b30de8dd 100644 --- a/tower/src/load/pending_requests.rs +++ b/tower/src/load/pending_requests.rs @@ -100,7 +100,7 @@ where #[cfg(feature = "discover")] impl PendingRequestsDiscover { /// Wraps a [`Discover`], wrapping all of its services with [`PendingRequests`]. - pub fn new(discover: D, completion: C) -> Self + pub const fn new(discover: D, completion: C) -> Self where D: Discover, D::Service: Service, diff --git a/tower/src/load_shed/error.rs b/tower/src/load_shed/error.rs index 3a4c025b4..e11da5825 100644 --- a/tower/src/load_shed/error.rs +++ b/tower/src/load_shed/error.rs @@ -14,7 +14,7 @@ pub struct Overloaded { impl Overloaded { /// Construct a new overloaded error - pub fn new() -> Self { + pub const fn new() -> Self { Overloaded { _p: () } } } diff --git a/tower/src/load_shed/layer.rs b/tower/src/load_shed/layer.rs index 65ab29f14..5585db796 100644 --- a/tower/src/load_shed/layer.rs +++ b/tower/src/load_shed/layer.rs @@ -13,7 +13,7 @@ pub struct LoadShedLayer { impl LoadShedLayer { /// Creates a new layer. - pub fn new() -> Self { + pub const fn new() -> Self { LoadShedLayer { _p: () } } } diff --git a/tower/src/load_shed/mod.rs b/tower/src/load_shed/mod.rs index deadf0fcb..422f30880 100644 --- a/tower/src/load_shed/mod.rs +++ b/tower/src/load_shed/mod.rs @@ -23,7 +23,7 @@ pub struct LoadShed { impl LoadShed { /// Wraps a service in [`LoadShed`] middleware. - pub fn new(inner: S) -> Self { + pub const fn new(inner: S) -> Self { LoadShed { inner, is_ready: false, diff --git a/tower/src/make/make_service/shared.rs b/tower/src/make/make_service/shared.rs index fd308a02a..2b2bc0265 100644 --- a/tower/src/make/make_service/shared.rs +++ b/tower/src/make/make_service/shared.rs @@ -75,7 +75,7 @@ pub struct Shared { impl Shared { /// Create a new [`Shared`] from a service. - pub fn new(service: S) -> Self { + pub const fn new(service: S) -> Self { Self { service } } } diff --git a/tower/src/reconnect/mod.rs b/tower/src/reconnect/mod.rs index ff354821c..80c6c2eb0 100644 --- a/tower/src/reconnect/mod.rs +++ b/tower/src/reconnect/mod.rs @@ -49,7 +49,7 @@ where M: Service, { /// Lazily connect and reconnect to a [`Service`]. - pub fn new(mk_service: M, target: Target) -> Self { + pub const fn new(mk_service: M, target: Target) -> Self { Reconnect { mk_service, state: State::Idle, diff --git a/tower/src/retry/layer.rs b/tower/src/retry/layer.rs index 830348582..f7f2c640b 100644 --- a/tower/src/retry/layer.rs +++ b/tower/src/retry/layer.rs @@ -9,7 +9,7 @@ pub struct RetryLayer

{ impl

RetryLayer

{ /// Creates a new [`RetryLayer`] from a retry policy. - pub fn new(policy: P) -> Self { + pub const fn new(policy: P) -> Self { RetryLayer { policy } } } diff --git a/tower/src/retry/mod.rs b/tower/src/retry/mod.rs index 3abd94fca..1bb5e29ed 100644 --- a/tower/src/retry/mod.rs +++ b/tower/src/retry/mod.rs @@ -49,7 +49,7 @@ pin_project! { impl Retry { /// Retry the inner service depending on this [`Policy`]. - pub fn new(policy: P, service: S) -> Self { + pub const fn new(policy: P, service: S) -> Self { Retry { policy, service } } diff --git a/tower/src/spawn_ready/service.rs b/tower/src/spawn_ready/service.rs index 7e6ea7920..d9573f50e 100644 --- a/tower/src/spawn_ready/service.rs +++ b/tower/src/spawn_ready/service.rs @@ -26,7 +26,7 @@ enum Inner { impl SpawnReady { /// Creates a new [`SpawnReady`] wrapping `service`. - pub fn new(service: S) -> Self { + pub const fn new(service: S) -> Self { Self { inner: Inner::Service(Some(service)), } diff --git a/tower/src/timeout/error.rs b/tower/src/timeout/error.rs index 223cada68..cc309b9c6 100644 --- a/tower/src/timeout/error.rs +++ b/tower/src/timeout/error.rs @@ -8,7 +8,7 @@ pub struct Elapsed(pub(super) ()); impl Elapsed { /// Construct a new elapsed error - pub fn new() -> Self { + pub const fn new() -> Self { Elapsed(()) } } diff --git a/tower/src/timeout/layer.rs b/tower/src/timeout/layer.rs index 3397fd85f..d8cc2d1c2 100644 --- a/tower/src/timeout/layer.rs +++ b/tower/src/timeout/layer.rs @@ -10,7 +10,7 @@ pub struct TimeoutLayer { impl TimeoutLayer { /// Create a timeout from a duration - pub fn new(timeout: Duration) -> Self { + pub const fn new(timeout: Duration) -> Self { TimeoutLayer { timeout } } } diff --git a/tower/src/timeout/mod.rs b/tower/src/timeout/mod.rs index 0e65a3f65..da3bbf98d 100644 --- a/tower/src/timeout/mod.rs +++ b/tower/src/timeout/mod.rs @@ -25,7 +25,7 @@ pub struct Timeout { impl Timeout { /// Creates a new [`Timeout`] - pub fn new(inner: T, timeout: Duration) -> Self { + pub const fn new(inner: T, timeout: Duration) -> Self { Timeout { inner, timeout } } diff --git a/tower/src/util/and_then.rs b/tower/src/util/and_then.rs index 819ca273c..adb9ada79 100644 --- a/tower/src/util/and_then.rs +++ b/tower/src/util/and_then.rs @@ -74,7 +74,7 @@ pub struct AndThenLayer { impl AndThen { /// Creates a new `AndThen` service. - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { AndThen { f, inner } } @@ -110,7 +110,7 @@ where impl AndThenLayer { /// Creates a new [`AndThenLayer`] layer. - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { AndThenLayer { f } } } diff --git a/tower/src/util/call_all/common.rs b/tower/src/util/call_all/common.rs index a4963473a..3b3f8938c 100644 --- a/tower/src/util/call_all/common.rs +++ b/tower/src/util/call_all/common.rs @@ -51,7 +51,7 @@ where S: Stream, Q: Drive, { - pub(crate) fn new(service: Svc, stream: S, queue: Q) -> CallAll { + pub(crate) const fn new(service: Svc, stream: S, queue: Q) -> CallAll { CallAll { service: Some(service), stream, diff --git a/tower/src/util/future_service.rs b/tower/src/util/future_service.rs index ef3a74914..c0a36df25 100644 --- a/tower/src/util/future_service.rs +++ b/tower/src/util/future_service.rs @@ -101,7 +101,7 @@ impl FutureService { /// /// This will most likely come up if you're calling `future_service` with an async block. In that /// case you can use `Box::pin(async { ... })` as shown in the example. - pub fn new(future: F) -> Self { + pub const fn new(future: F) -> Self { Self { state: State::Future(future), } diff --git a/tower/src/util/map_err.rs b/tower/src/util/map_err.rs index b79c5fee2..1b936acbc 100644 --- a/tower/src/util/map_err.rs +++ b/tower/src/util/map_err.rs @@ -42,7 +42,7 @@ opaque_future! { impl MapErr { /// Creates a new [`MapErr`] service. - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { MapErr { f, inner } } @@ -78,7 +78,7 @@ where impl MapErrLayer { /// Creates a new [`MapErrLayer`]. - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { MapErrLayer { f } } } diff --git a/tower/src/util/map_future.rs b/tower/src/util/map_future.rs index 9f5670add..55bf96d07 100644 --- a/tower/src/util/map_future.rs +++ b/tower/src/util/map_future.rs @@ -17,7 +17,7 @@ pub struct MapFuture { impl MapFuture { /// Creates a new [`MapFuture`] service. - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { Self { inner, f } } @@ -88,7 +88,7 @@ pub struct MapFutureLayer { impl MapFutureLayer { /// Creates a new [`MapFutureLayer`] layer. - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { Self { f } } } diff --git a/tower/src/util/map_request.rs b/tower/src/util/map_request.rs index e86e0680b..62f2de3cb 100644 --- a/tower/src/util/map_request.rs +++ b/tower/src/util/map_request.rs @@ -26,7 +26,7 @@ where impl MapRequest { /// Creates a new [`MapRequest`] service. - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { MapRequest { inner, f } } @@ -70,7 +70,7 @@ pub struct MapRequestLayer { impl MapRequestLayer { /// Creates a new [`MapRequestLayer`]. - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { MapRequestLayer { f } } } diff --git a/tower/src/util/map_response.rs b/tower/src/util/map_response.rs index 249be3a4d..8edac10aa 100644 --- a/tower/src/util/map_response.rs +++ b/tower/src/util/map_response.rs @@ -42,7 +42,7 @@ opaque_future! { impl MapResponse { /// Creates a new `MapResponse` service. - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { MapResponse { f, inner } } @@ -78,7 +78,7 @@ where impl MapResponseLayer { /// Creates a new [`MapResponseLayer`] layer. - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { MapResponseLayer { f } } } diff --git a/tower/src/util/map_result.rs b/tower/src/util/map_result.rs index bfe16b5b4..5a96af2d1 100644 --- a/tower/src/util/map_result.rs +++ b/tower/src/util/map_result.rs @@ -42,7 +42,7 @@ opaque_future! { impl MapResult { /// Creates a new [`MapResult`] service. - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { MapResult { f, inner } } @@ -79,7 +79,7 @@ where impl MapResultLayer { /// Creates a new [`MapResultLayer`] layer. - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { MapResultLayer { f } } } diff --git a/tower/src/util/oneshot.rs b/tower/src/util/oneshot.rs index 93b5070be..114b2f825 100644 --- a/tower/src/util/oneshot.rs +++ b/tower/src/util/oneshot.rs @@ -35,11 +35,11 @@ pin_project! { } impl, Req> State { - fn not_ready(svc: S, req: Option) -> Self { + const fn not_ready(svc: S, req: Option) -> Self { Self::NotReady { svc, req } } - fn called(fut: S::Future) -> Self { + const fn called(fut: S::Future) -> Self { Self::Called { fut } } } @@ -71,7 +71,7 @@ where S: Service, { #[allow(missing_docs)] - pub fn new(svc: S, req: Req) -> Self { + pub const fn new(svc: S, req: Req) -> Self { Oneshot { state: State::not_ready(svc, Some(req)), } diff --git a/tower/src/util/optional/mod.rs b/tower/src/util/optional/mod.rs index 8ba3ab95d..4d0207093 100644 --- a/tower/src/util/optional/mod.rs +++ b/tower/src/util/optional/mod.rs @@ -23,7 +23,7 @@ pub struct Optional { impl Optional { /// Create a new [`Optional`]. - pub fn new(inner: Option) -> Optional + pub const fn new(inner: Option) -> Optional where T: Service, T::Error: Into, diff --git a/tower/src/util/ready.rs b/tower/src/util/ready.rs index 668d50143..750db872f 100644 --- a/tower/src/util/ready.rs +++ b/tower/src/util/ready.rs @@ -26,7 +26,7 @@ where T: Service, { #[allow(missing_docs)] - pub fn new(service: T) -> Self { + pub const fn new(service: T) -> Self { Self { inner: Some(service), _p: PhantomData, diff --git a/tower/src/util/then.rs b/tower/src/util/then.rs index 1ec3c1492..5e9345067 100644 --- a/tower/src/util/then.rs +++ b/tower/src/util/then.rs @@ -38,7 +38,7 @@ pub struct ThenLayer { impl Then { /// Creates a new `Then` service. - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { Then { f, inner } } @@ -83,7 +83,7 @@ where impl ThenLayer { /// Creates a new [`ThenLayer`] layer. - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { ThenLayer { f } } }