Expand description
§Load Balancer Library
This library provides a set of generic load balancer implementations for distributing workloads across multiple targets, such as clients, network endpoints, or resources.
§Traits
§LoadBalancer<T>
A generic trait for asynchronous or synchronous load balancing. Implementors provide methods to allocate a resource from the pool.
use std::future::Future;
pub trait LoadBalancer<T>: Send + Sync + Clone + 'static {
/// Asynchronously allocate a resource.
fn alloc(&self) -> impl Future<Output = T> + Send;
/// Attempt to allocate a resource synchronously without awaiting.
fn try_alloc(&self) -> Option<T>;
}§BoxLoadBalancer<T>
An async trait variant that can be used with async_trait for boxed trait objects
or dynamic dispatch. Provides similar functionality to LoadBalancer but supports
fully async method signatures.
use async_trait::async_trait;
#[async_trait]
pub trait BoxLoadBalancer<T>: Send + Sync + Clone + 'static {
/// Asynchronously allocate a resource.
async fn alloc(&self) -> T;
/// Attempt to allocate a resource synchronously without awaiting.
fn try_alloc(&self) -> Option<T>;
}