Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs pass #490

Merged
merged 11 commits into from
Jan 4, 2021
5 changes: 4 additions & 1 deletion tower-layer/src/layer_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ use std::fmt;
/// Ok::<_, Infallible>(request.to_uppercase())
/// });
///
/// // Wrap our servic in a `LogService` so requests are logged.
/// // Wrap our service in a `LogService` so requests are logged.
/// let wrapped_service = log_layer.layer(uppercase_service);
/// ```
///
/// [`Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html
/// [`Layer::layer`]: crate::Layer::layer
pub fn layer_fn<T>(f: T) -> LayerFn<T> {
LayerFn { f }
}
Expand Down
1 change: 1 addition & 0 deletions tower-test/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/// assert_eq!(response.await.unwrap(), "world");
/// # }
/// ```
/// [`SendResponse`]: crate::mock::SendResponse
#[macro_export]
macro_rules! assert_request_eq {
($mock_handle:expr, $expect:expr) => {
Expand Down
7 changes: 4 additions & 3 deletions tower/src/balance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
//!
//! Second, [`pool`] implements a dynamically sized pool of services. It estimates the overall
//! current load by tracking successful and unsuccessful calls to `poll_ready`, and uses an
//! exponentially weighted moving average to add (using [`tower::make_service::MakeService`]) or
//! remove (by dropping) services in response to increases or decreases in load. Use this if you
//! are able to dynamically add more service endpoints to the system to handle added load.
//! exponentially weighted moving average to add (using [`MakeService`]) or remove (by dropping)
//! services in response to increases or decreases in load. Use this if you are able to
//! dynamically add more service endpoints to the system to handle added load.
//!
//! # Examples
//!
Expand Down Expand Up @@ -52,6 +52,7 @@
//! }
//! # }
//! ```
//! [`MakeService`]: crate::MakeService

pub mod error;
pub mod p2c;
Expand Down
13 changes: 9 additions & 4 deletions tower/src/balance/p2c/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ use tower_layer::Layer;
///
/// This construction may seem a little odd at first glance. This is not a layer that takes
/// requests and produces responses in the traditional sense. Instead, it is more like
/// [`MakeService`](tower::make_service::MakeService) in that it takes service _descriptors_ (see
/// `Target` on `MakeService`) and produces _services_. Since [`Balance`] spreads requests across a
/// _set_ of services, the inner service should produce a [`Discover`], not just a single
/// [`MakeService`] in that it takes service _descriptors_ (see `Target` on `MakeService`)
/// and produces _services_. Since [`Balance`] spreads requests across a _set_ of services,
/// the inner service should produce a [`Discover`], not just a single
/// [`Service`], given a service descriptor.
///
/// See the [module-level documentation](..) for details on load balancing.
/// See the [module-level documentation](crate::balance) for details on load balancing.
///
/// [`Balance`]: crate::balance::p2c::Balance
/// [`Discover`]: crate::discover::Discover
/// [`MakeService`]: crate::MakeService
/// [`Service`]: crate::Service
#[derive(Clone)]
pub struct MakeBalanceLayer<D, Req> {
_marker: PhantomData<fn(D, Req)>,
Expand Down
16 changes: 11 additions & 5 deletions tower/src/balance/p2c/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ use tower_service::Service;

/// Constructs load balancers over dynamic service sets produced by a wrapped "inner" service.
///
/// This is effectively an implementation of [`MakeService`](tower::make_service::MakeService),
/// except that it forwards the service descriptors (`Target`) to an inner service (`S`), and
/// expects that service to produce a service set in the form of a [`Discover`]. It then wraps the
/// service set in a [`Balance`] before returning it as the "made" service.
/// This is effectively an implementation of [`MakeService`] except that it forwards the service
/// descriptors (`Target`) to an inner service (`S`), and expects that service to produce a
/// service set in the form of a [`Discover`]. It then wraps the service set in a [`Balance`]
/// before returning it as the "made" service.
///
/// See the [module-level documentation](..) for details on load balancing.
/// See the [module-level documentation](crate::balance) for details on load balancing.
///
/// [`MakeService`]: crate::MakeService
/// [`Discover`]: crate::discover::Discover
/// [`Balance`]: crate::balance::p2c::Balance
#[derive(Clone, Debug)]
pub struct MakeBalance<S, Req> {
inner: S,
_marker: PhantomData<fn(Req)>,
}

/// A [`Balance`] in the making.
///
/// [`Balance`]: crate::balance::p2c::Balance
#[pin_project]
#[derive(Debug)]
pub struct MakeFuture<F, Req> {
Expand Down
6 changes: 3 additions & 3 deletions tower/src/balance/p2c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! It is a simple but robust technique for spreading load across services with only inexact load
//! measurements. As its name implies, whenever a request comes in, it samples two ready services
//! at random, and issues the request to whichever service is less loaded. How loaded a service is
//! is determined by the return value of [`Load`](tower::load::Load).
//! is determined by the return value of [`Load`](crate::load::Load).
//!
//! As described in the [Finagle Guide][finagle]:
//!
Expand All @@ -16,9 +16,9 @@
//!
//! The balance service and layer implementations rely on _service discovery_ to provide the
//! underlying set of services to balance requests across. This happens through the
//! [`Discover`](tower::discover::Discover) trait, which is essentially a `Stream` that indicates
//! [`Discover`](crate::discover::Discover) trait, which is essentially a `Stream` that indicates
//! when services become available or go away. If you have a fixed set of services, consider using
//! [`ServiceList`](tower::discover::ServiceList).
//! [`ServiceList`](crate::discover::ServiceList).
//!
//! 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
Expand Down
Loading