Struct Balance
pub struct Balance<D, Req>
where
D: Discover,
D::Key: Hash, { /* private fields */ }
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>
where
D: Discover,
D::Key: Hash,
D::Service: Service<Req>,
<D::Service as Service<Req>>::Error: Into<BoxError>,
fn new(discover: D) -> SelfConstructs a load balancer that uses operating system entropy.
fn from_rng<R: Rng + Send + Sync + 'static>(discover: D, rng: R) -> SelfConstructs a load balancer seeded with the provided random number generator.
fn len(&self) -> usizeReturns the number of endpoints currently tracked by the balancer.
fn is_empty(&self) -> boolReturns whether or not the balancer is empty.
Trait Implementations
impl<D, Req> Debug for Balance<D, Req>
where
D: Debug + Discover,
D::Key: Hash + Debug,
D::Service: Debug,
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<D, Req> Service<Req> for Balance<D, Req>
where
D: Discover + Unpin,
D::Key: Hash + Clone,
D::Error: Into<BoxError>,
D::Service: Service<Req> + Load,
<D::Service as Load>::Metric: Debug,
<D::Service as Service<Req>>::Error: Into<BoxError>,
type Response = <<D as Discover>::Service as Service<Req>>::Response;type Error = Box<dyn Error + Sync + Send>;type Future = MapErr<<<D as Discover>::Service as Service<Req>>::Future, fn(<<D as Discover>::Service as Service<Req>>::Error) -> Box<dyn Error + Sync + Send>>;fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>fn call(&mut self, request: Req) -> Self::Future