net-pool 0.5.1

A set of types for network connection pool.
Documentation
use crate::backend::{Address, BackendState};

/// 策略trait
pub trait Strategy: Send + Sync {
    /// 判断一个后端地址是否存在
    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>;

    /// 获取id来获取后端地址
    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>;
    
    /// 获取一个后端地址, 通过通用key
    fn backend<KEY: AsRef<str>>(this: Box<dyn Strategy>, key: KEY) -> Option<BackendState>
    where
        Self: Sized,
    {
        this.get_backend(key.as_ref())
    }
}