Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tim/clone-sync-service
Browse files Browse the repository at this point in the history
  • Loading branch information
tthebst committed Jul 22, 2024
2 parents 1f2711a + 74e925d commit ae407cc
Show file tree
Hide file tree
Showing 56 changed files with 83 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request: {}

env:
MSRV: 1.49.0
MSRV: 1.63.0

jobs:
check-stable:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pattern. If your protocol is entirely stream based, Tower may not be a good fit.

Tower will keep a rolling MSRV (minimum supported Rust version) policy of **at
least** 6 months. When increasing the MSRV, the new Rust version must have been
released at least six months ago. The current MSRV is 1.49.0.
released at least six months ago. The current MSRV is 1.63.0.

## Getting Started

Expand Down
1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
vulnerability = "deny"
unmaintained = "warn"
notice = "warn"
ignore = ["RUSTSEC-2020-0159"]

[licenses]
unlicensed = "deny"
Expand Down
6 changes: 3 additions & 3 deletions guides/building-a-middleware-from-scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ means we can combine multiple errors type into one. That has the following
advantages:

1. Our error handling is less fragile since changing the order middleware are
applied in wont change the final error type.
applied in won't change the final error type.
2. The error type now has a constant size regardless how many middleware we've
applied.
3. Extracting the error no longer requires a big `match` but can instead be done
Expand All @@ -412,7 +412,7 @@ For our `Timeout` middleware that means we need to create a struct that
implements `std::error::Error` such that we can convert it into a `Box<dyn
std::error::Error + Send + Sync>`. We also have to require that the inner
service's error type implements `Into<Box<dyn std::error::Error + Send +
Sync>>`. Luckily most errors automatically satisfies that so it wont require
Sync>>`. Luckily most errors automatically satisfies that so it won't require
users to write any additional code. We're using `Into` for the trait bound
rather than `From` as recommend by the [standard
library](https://doc.rust-lang.org/stable/std/convert/trait.From.html).
Expand Down Expand Up @@ -521,7 +521,7 @@ where

## Conclusion

Thats it! We've now successfully implemented the `Timeout` middleware as it
That's it! We've now successfully implemented the `Timeout` middleware as it
exists in Tower today.

Our final implementation is:
Expand Down
2 changes: 1 addition & 1 deletion tower-layer/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: () }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tower-layer/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Stack<Inner, Outer> {

impl<Inner, Outer> Stack<Inner, Outer> {
/// Create a new `Stack`.
pub fn new(inner: Inner, outer: Outer) -> Self {
pub const fn new(inner: Inner, outer: Outer) -> Self {
Stack { inner, outer }
}
}
Expand Down
4 changes: 2 additions & 2 deletions tower-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ use std::task::{Context, Poll};
/// }
///
/// impl<T> Timeout<T> {
/// pub fn new(inner: T, timeout: Duration) -> Timeout<T> {
/// pub const fn new(inner: T, timeout: Duration) -> Timeout<T> {
/// Timeout {
/// inner,
/// timeout
Expand Down Expand Up @@ -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)
/// }
/// }
Expand Down
4 changes: 2 additions & 2 deletions tower/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ clients and servers.
categories = ["asynchronous", "network-programming"]
keywords = ["io", "async", "non-blocking", "futures", "service"]
edition = "2018"
rust-version = "1.49.0"
rust-version = "1.63.0"

[features]

Expand Down Expand Up @@ -71,7 +71,7 @@ tower-service = { version = "0.3.1", path = "../tower-service" }
futures-core = { version = "0.3", optional = true }
futures-util = { version = "0.3", default-features = false, features = ["alloc"], optional = true }
hdrhistogram = { version = "7.0", optional = true, default-features = false }
indexmap = { version = "1.0.2", optional = true }
indexmap = { version = "2.0.2", optional = true }
slab = { version = "0.4", optional = true }
tokio = { version = "1.6", optional = true, features = ["sync"] }
tokio-stream = { version = "0.1.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion tower/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Tower.

Tower will keep a rolling MSRV (minimum supported Rust version) policy of **at
least** 6 months. When increasing the MSRV, the new Rust version must have been
released at least six months ago. The current MSRV is 1.49.0.
released at least six months ago. The current MSRV is 1.63.0.

## License

Expand Down
2 changes: 1 addition & 1 deletion tower/src/balance/p2c/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct MakeBalanceLayer<D, Req> {

impl<D, Req> MakeBalanceLayer<D, Req> {
/// Build balancers using operating system entropy.
pub fn new() -> Self {
pub const fn new() -> Self {
Self {
_marker: PhantomData,
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/balance/p2c/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pin_project! {

impl<S, Req> MakeBalance<S, Req> {
/// 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,
Expand Down
2 changes: 1 addition & 1 deletion tower/src/balance/p2c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! Since the load balancer needs to perform _random_ choices, the constructors in this module
//! usually come in two forms: one that uses randomness provided by the operating system, and one
//! that lets you specify the random seed to use. Usually the former is what you'll want, though
//! the latter may come in handy for reproducability or to reduce reliance on the operating system.
//! the latter may come in handy for reproducibility or to reduce reliance on the operating system.
//!
//! [Power of Two Random Choices]: http://www.eecs.harvard.edu/~michaelm/postscripts/handbook2001.pdf
//! [finagle]: https://twitter.github.io/finagle/guide/Clients.html#power-of-two-choices-p2c-least-loaded
Expand Down
2 changes: 1 addition & 1 deletion tower/src/buffer/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<Request> BufferLayer<Request> {
/// [`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,
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 @@ -115,7 +115,7 @@ impl Default for ServiceBuilder<Identity> {

impl ServiceBuilder<Identity> {
/// Create a new [`ServiceBuilder`].
pub fn new() -> Self {
pub const fn new() -> Self {
ServiceBuilder {
layer: Identity::new(),
}
Expand Down
4 changes: 2 additions & 2 deletions tower/src/filter/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<U> FilterLayer<U> {
///
/// [`Predicate`]: crate::filter::Predicate
/// [`Filter`]: crate::filter::Filter
pub fn new(predicate: U) -> Self {
pub const fn new(predicate: U) -> Self {
Self { predicate }
}
}
Expand All @@ -57,7 +57,7 @@ impl<U> AsyncFilterLayer<U> {
///
/// [`AsyncPredicate`]: crate::filter::AsyncPredicate
/// [`Filter`]: crate::filter::Filter
pub fn new(predicate: U) -> Self {
pub const fn new(predicate: U) -> Self {
Self { predicate }
}
}
Expand Down
4 changes: 2 additions & 2 deletions tower/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct AsyncFilter<T, U> {

impl<T, U> Filter<T, U> {
/// 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 }
}

Expand Down Expand Up @@ -123,7 +123,7 @@ where

impl<T, U> AsyncFilter<T, U> {
/// 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 }
}

Expand Down
2 changes: 1 addition & 1 deletion tower/src/hedge/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<Request, F> State<Request, F> {
}

impl<P, S> Delay<P, S> {
pub fn new<Request>(policy: P, service: S) -> Self
pub const fn new<Request>(policy: P, service: S) -> Self
where
P: Policy<Request>,
S: Service<Request> + Clone,
Expand Down
2 changes: 1 addition & 1 deletion tower/src/hedge/latency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<S, R> Latency<R, S>
where
R: Record + Clone,
{
pub fn new<Request>(rec: R, service: S) -> Self
pub const fn new<Request>(rec: R, service: S) -> Self
where
S: Service<Request>,
S::Error: Into<crate::BoxError>,
Expand Down
2 changes: 1 addition & 1 deletion tower/src/hedge/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pin_project! {
}

impl<P, A, B> Select<P, A, B> {
pub fn new<Request>(policy: P, a: A, b: B) -> Self
pub const fn new<Request>(policy: P, a: A, b: B) -> Self
where
P: Policy<Request>,
A: Service<Request>,
Expand Down
7 changes: 6 additions & 1 deletion tower/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
//!
//! Tower will keep a rolling MSRV (minimum supported Rust version) policy of **at
//! least** 6 months. When increasing the MSRV, the new Rust version must have been
//! released at least six months ago. The current MSRV is 1.49.0.
//! released at least six months ago. The current MSRV is 1.63.0.
//!
//! [`Service`]: crate::Service
//! [`Layer`]: crate::Layer
Expand Down Expand Up @@ -202,15 +202,20 @@ pub mod layer;

#[cfg(feature = "util")]
#[doc(inline)]
#[cfg_attr(docsrs, doc(cfg(feature = "util")))]
pub use self::util::{service_fn, ServiceExt};

#[doc(inline)]
pub use crate::builder::ServiceBuilder;

#[cfg(feature = "make")]
#[doc(inline)]
#[cfg_attr(docsrs, doc(cfg(feature = "make")))]
pub use crate::make::MakeService;

#[doc(inline)]
pub use tower_layer::Layer;

#[doc(inline)]
pub use tower_service::Service;

Expand Down
2 changes: 1 addition & 1 deletion tower/src/limit/concurrency/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/limit/rate/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
4 changes: 2 additions & 2 deletions tower/src/limit/rate/rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.as_nanos() > 0);

Rate { num, per }
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/load/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pin_project! {

impl<F, C, H> TrackCompletionFuture<F, C, H> {
/// 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,
Expand Down
2 changes: 1 addition & 1 deletion tower/src/load/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pin_project! {

impl<T, M: Copy> Constant<T, M> {
/// 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 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/load/pending_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
#[cfg(feature = "discover")]
impl<D, C> PendingRequestsDiscover<D, C> {
/// Wraps a [`Discover`], wrapping all of its services with [`PendingRequests`].
pub fn new<Request>(discover: D, completion: C) -> Self
pub const fn new<Request>(discover: D, completion: C) -> Self
where
D: Discover,
D::Service: Service<Request>,
Expand Down
2 changes: 1 addition & 1 deletion tower/src/load_shed/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: () }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/load_shed/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct LoadShedLayer {

impl LoadShedLayer {
/// Creates a new layer.
pub fn new() -> Self {
pub const fn new() -> Self {
LoadShedLayer { _p: () }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/load_shed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct LoadShed<S> {

impl<S> LoadShed<S> {
/// Wraps a service in [`LoadShed`] middleware.
pub fn new(inner: S) -> Self {
pub const fn new(inner: S) -> Self {
LoadShed {
inner,
is_ready: false,
Expand Down
2 changes: 1 addition & 1 deletion tower/src/make/make_service/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct Shared<S> {

impl<S> Shared<S> {
/// Create a new [`Shared`] from a service.
pub fn new(service: S) -> Self {
pub const fn new(service: S) -> Self {
Self { service }
}
}
Expand Down
4 changes: 2 additions & 2 deletions tower/src/ready_cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use tracing::{debug, trace};
/// in the ready set. The `ReadyCache::check_*` functions can be used to ensure
/// that a service is ready before dispatching a request.
///
/// The ready set can hold services for an abitrarily long time. During this
/// The ready set can hold services for an arbitrarily long time. During this
/// time, the runtime may process events that invalidate that ready state (for
/// instance, if a keepalive detects a lost connection). In such cases, callers
/// should use [`ReadyCache::check_ready`] (or [`ReadyCache::check_ready_index`])
Expand Down Expand Up @@ -193,7 +193,7 @@ where
}

/// Obtains a mutable reference to a service in the ready set by index.
pub fn get_ready_index_mut(&mut self, idx: usize) -> Option<(&mut K, &mut S)> {
pub fn get_ready_index_mut(&mut self, idx: usize) -> Option<(&K, &mut S)> {
self.ready.get_index_mut(idx).map(|(k, v)| (k, &mut v.0))
}

Expand Down
4 changes: 2 additions & 2 deletions tower/src/reconnect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where
M: Service<Target>,
{
/// Lazily connect and reconnect to a [`Service`].
pub fn new<S, Request>(mk_service: M, target: Target) -> Self {
pub const fn new(mk_service: M, target: Target) -> Self {
Reconnect {
mk_service,
state: State::Idle,
Expand All @@ -59,7 +59,7 @@ where
}

/// Reconnect to a already connected [`Service`].
pub fn with_connection(init_conn: M::Response, mk_service: M, target: Target) -> Self {
pub const fn with_connection(init_conn: M::Response, mk_service: M, target: Target) -> Self {
Reconnect {
mk_service,
state: State::Connected(init_conn),
Expand Down
2 changes: 1 addition & 1 deletion tower/src/retry/backoff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This module contains generic [backoff] utlities to be used with the retry
//! This module contains generic [backoff] utilities to be used with the retry
//! layer.
//!
//! The [`Backoff`] trait is a generic way to represent backoffs that can use
Expand Down
2 changes: 1 addition & 1 deletion tower/src/retry/budget/tps_budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct TpsBudget {
slots: Box<[AtomicIsize]>,
/// The amount of time represented by each slot.
window: Duration,
/// The changers for the current slot to be commited
/// The changers for the current slot to be committed
/// after the slot expires.
writer: AtomicIsize,
/// Amount of tokens to deposit for each put().
Expand Down
Loading

0 comments on commit ae407cc

Please sign in to comment.