1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! # 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>;
//! }
//! ```
//!
//! ### `FilteredLoadBalancer<T>`
//!
//! A trait for load balancers that support predicate-based filtering. Unlike
//! [`LoadBalancer`], filter methods return `(usize, T)` — the entry index
//! alongside the value — so callers can identify the allocated entry.
//!
//! ```rust
//! use std::future::Future;
//!
//! pub trait FilteredLoadBalancer<T>: Send + Sync + Clone + 'static {
//! /// Asynchronously allocate an entry that satisfies the given predicate.
//! fn alloc_filter(
//! &self,
//! predicate: impl FnMut((usize, &T)) -> bool,
//! ) -> impl Future<Output = (usize, T)> + Send;
//!
//! /// Attempt to allocate an entry that satisfies the predicate without awaiting.
//! fn try_alloc_filter(
//! &self,
//! predicate: impl FnMut((usize, &T)) -> bool,
//! ) -> Option<(usize, T)>;
//! }
//! ```
/// Cooldown-based load balancer with per-entry reuse intervals.
/// Fault-tolerant load balancer with error tracking and auto-disabling.
/// Proxy pool with health checking and latency-based sorting.
/// Random selection load balancer.
/// Fixed-window rate limiter (single + per-key map).
/// Round-robin sequential load balancer.
/// Sliding-window load balancer with per-entry rate limits.
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.).
/// A load balancer that supports predicate-based filtering during allocation.
///
/// Unlike [`LoadBalancer`], filter methods return `(usize, T)` so callers
/// can identify the allocated entry (e.g. for error feedback).