use crate::backend::{Address, BackendState};
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Strategy {
Hash,
ConsistentHash,
RoundRobin,
}
pub trait LbStrategy: Send + Sync {
fn strategy(&self) -> Strategy;
fn contain(&self, addr: &Address) -> bool;
fn add_backend(&self, addr: Address);
fn remove_backend(&self, addr: &Address) -> bool;
fn get_backend(&self, key: &str) -> Option<BackendState>;
fn get_backends(&self) -> Vec<BackendState>;
fn backend<KEY: AsRef<str>>(this: Box<dyn LbStrategy>, key: KEY) -> Option<BackendState>
where
Self: Sized,
{
this.get_backend(key.as_ref())
}
}