net_pool/strategy/
strategy.rs1use crate::backend::{Address, BackendState};
2
3#[derive(Debug, Clone, Eq, PartialEq)]
4pub enum Strategy {
5 Hash,
7
8 ConsistentHash,
10
11 RoundRobin,
13}
14
15pub trait LbStrategy: Send + Sync {
17 fn strategy(&self) -> Strategy;
19
20 fn contain(&self, addr: &Address) -> bool;
22
23 fn add_backend(&self, addr: Address);
25
26 fn remove_backend(&self, addr: &Address) -> bool;
28
29 fn get_backend(&self, key: &str) -> Option<BackendState>;
31
32 fn get_backends(&self) -> Vec<BackendState>;
34
35 fn backend<KEY: AsRef<str>>(this: Box<dyn LbStrategy>, key: KEY) -> Option<BackendState>
37 where
38 Self: Sized,
39 {
40 this.get_backend(key.as_ref())
41 }
42}