load-balancer 0.5.0

Asynchronous load balancing utilities for Rust — round-robin, random, cooldown, window, fault-tolerant, proxy pool with health checks, and token-bucket rate limiting.
Documentation
//! # 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.
//!
//! ```rust
//! 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>;
//! }
//! ```

/// Cooldown-based load balancer with per-entry reuse intervals.
pub mod cooldown;
/// Fault-tolerant load balancer with error tracking and auto-disabling.
pub mod fault_tolerant;
/// Proxy pool with health checking and latency-based sorting.
pub mod proxy_pool;
/// Random selection load balancer.
pub mod random;
/// Token-bucket rate limiter.
pub mod rate_limit;
/// Round-robin sequential load balancer.
pub mod round_robin;
/// Sliding-window load balancer with per-entry rate limits.
pub mod window;

pub use anyhow;
pub use dashmap;
pub use reqwest;

/// A generic load balancer trait for allocating resources from a pool.
///
/// Implementors manage a collection of items and distribute them according to
/// their specific strategy (round-robin, random, cooldown, etc.).
pub trait LoadBalancer<T>: Send + Sync + Clone + 'static {
    /// Asynchronously allocate a resource from the pool.
    fn alloc(&self) -> impl Future<Output = T> + Send;
    /// Attempt to allocate a resource synchronously without awaiting.
    fn try_alloc(&self) -> Option<T>;
}