br-addon 0.2.20

This is an addon
Documentation
#[cfg(feature = "cache")]
use br_cache::{Cache, Config as CacheConfig};
#[cfg(any(
    feature = "mysql",
    feature = "mssql",
    feature = "sqlite",
    feature = "pgsql"
))]
use br_db::config::Config as DbConfig;
#[cfg(any(
    feature = "mysql",
    feature = "mssql",
    feature = "sqlite",
    feature = "pgsql"
))]
use br_db::Db;
use serde::Deserialize;
use std::path::Path;

#[derive(Clone)]
pub struct Tools {
    #[cfg(any(
        feature = "mysql",
        feature = "mssql",
        feature = "sqlite",
        feature = "pgsql"
    ))]
    pub db: Db,
    #[cfg(feature = "cache")]
    pub cache: Cache,
}
impl Tools {
    pub fn new(config: ToolsConfig) -> Result<Self, String> {
        Ok(Self {
            #[cfg(any(
                feature = "mysql",
                feature = "mssql",
                feature = "sqlite",
                feature = "pgsql"
            ))]
            db: Db::new(config.db)?,
            #[cfg(feature = "cache")]
            cache: Cache::new(config.cache),
        })
    }
}
#[derive(Clone, Debug, Deserialize)]
pub struct ToolsConfig {
    #[cfg(any(
        feature = "mysql",
        feature = "mssql",
        feature = "sqlite",
        feature = "pgsql"
    ))]
    pub db: DbConfig,
    #[cfg(feature = "cache")]
    pub cache: CacheConfig,
}
impl ToolsConfig {
    #[must_use]
    pub fn create(config_file: &Path) -> Self {
        Self {
            #[cfg(any(
                feature = "mysql",
                feature = "mssql",
                feature = "sqlite",
                feature = "pgsql"
            ))]
            db: DbConfig::create(config_file.to_path_buf(), true),
            #[cfg(feature = "cache")]
            cache: CacheConfig::create(config_file.to_path_buf(), true),
        }
    }
}