Struct Balance

struct Balance<D, Req> { ... }
where
    D: Discover,
    <D as >::Key: Hash

Efficiently distributes requests across an arbitrary number of services.

See the module-level documentation for details.

Note that Balance requires that the Discover you use is Unpin in order to implement Service. This is because it needs to be accessed from Service::poll_ready, which takes &mut self. You can achieve this easily by wrapping your Discover in Box::pin before you construct the Balance instance. For more details, see #319.

Implementations

impl<D, Req> Balance<D, Req>

fn new(discover: D) -> Self

Constructs a load balancer that uses operating system entropy.

fn from_rng<R: Rng + Send + Sync + 'static>(discover: D, rng: R) -> Self

Constructs a load balancer seeded with the provided random number generator.

fn len(self: &Self) -> usize

Returns the number of endpoints currently tracked by the balancer.

fn is_empty(self: &Self) -> bool

Returns whether or not the balancer is empty.

impl<D, Req> Debug for Balance<D, Req>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<D, Req> Freeze for Balance<D, Req>

impl<D, Req> RefUnwindSafe for Balance<D, Req>

impl<D, Req> Send for Balance<D, Req>

impl<D, Req> Service for Balance<D, Req>

fn poll_ready(self: &mut Self, cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>>
fn call(self: &mut Self, request: Req) -> <Self as >::Future

impl<D, Req> Sync for Balance<D, Req>

impl<D, Req> Unpin for Balance<D, Req>

impl<D, Req> UnsafeUnpin for Balance<D, Req>

impl<D, Req> UnwindSafe for Balance<D, Req>

impl<M, S, Target, Request> MakeService for Balance<D, Req>

fn poll_ready(self: &mut Self, cx: &mut Context<'_>) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
fn make_service(self: &mut Self, target: Target) -> <M as MakeService<Target, Request>>::Future

impl<T> Any for Balance<D, Req>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Balance<D, Req>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Balance<D, Req>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for Balance<D, Req>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Balance<D, Req>

impl<T> WithSubscriber for Balance<D, Req>

impl<T, Request> ServiceExt for Balance<D, Req>

impl<T, U> Into for Balance<D, Req>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Balance<D, Req>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Balance<D, Req>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>