pub trait Strategy: Send + Sync {
// Required methods
fn contain(&self, addr: &Address) -> bool;
fn add_backend(&self, id: Option<u32>, addr: Address);
fn remove_backend(&self, addr: &Address) -> bool;
fn get_backend(&self, key: &str) -> Option<BackendState>;
fn get_backend_by_id(&self, id: u32) -> Option<BackendState>;
fn get_backend_by_code(&self, code: u64) -> Option<BackendState>;
fn get_backends(&self) -> Vec<BackendState>;
// Provided method
fn backend<KEY: AsRef<str>>(
this: Box<dyn Strategy>,
key: KEY,
) -> Option<BackendState>
where Self: Sized { ... }
}Expand description
策略trait
Required Methods§
Sourcefn add_backend(&self, id: Option<u32>, addr: Address)
fn add_backend(&self, id: Option<u32>, addr: Address)
添加一个后端地址
Sourcefn remove_backend(&self, addr: &Address) -> bool
fn remove_backend(&self, addr: &Address) -> bool
移除一个后端地址
Sourcefn get_backend(&self, key: &str) -> Option<BackendState>
fn get_backend(&self, key: &str) -> Option<BackendState>
获取一个后端地址
Sourcefn get_backend_by_id(&self, id: u32) -> Option<BackendState>
fn get_backend_by_id(&self, id: u32) -> Option<BackendState>
获取id来获取后端地址
fn get_backend_by_code(&self, code: u64) -> Option<BackendState>
Sourcefn get_backends(&self) -> Vec<BackendState>
fn get_backends(&self) -> Vec<BackendState>
获取所有后端地址