pub struct Config;Expand description
Main Config facade for accessing configuration
The Config struct provides a centralized way to initialize and access application configuration. It follows the Laravel pattern of type-safe configuration with environment variable support.
Implementations§
Source§impl Config
impl Config
Sourcepub fn init(project_root: &Path) -> Environment
pub fn init(project_root: &Path) -> Environment
Initialize the configuration system
This should be called at application startup, before creating the server.
It loads environment variables from .env files and registers default configs.
§Arguments
project_root- Path to the project root where.envfiles are located
§Returns
The detected environment (Local, Development, Production, etc.)
§Example
use kit::Config;
let env = Config::init(std::path::Path::new("."));
println!("Running in {} environment", env);Sourcepub fn get<T: Any + Send + Sync + Clone + 'static>() -> Option<T>
pub fn get<T: Any + Send + Sync + Clone + 'static>() -> Option<T>
Get a typed config struct from the repository
§Example
use kit::{Config, ServerConfig};
let server_config = Config::get::<ServerConfig>().unwrap();
println!("Port: {}", server_config.port);Sourcepub fn register<T: Any + Send + Sync + 'static>(config: T)
pub fn register<T: Any + Send + Sync + 'static>(config: T)
Register a custom config struct
Use this to register your own configuration structs that can be
retrieved later with Config::get::<T>().
§Example
use kit::Config;
#[derive(Clone)]
struct DatabaseConfig {
host: String,
port: u16,
}
Config::register(DatabaseConfig {
host: "localhost".to_string(),
port: 5432,
});Sourcepub fn environment() -> Environment
pub fn environment() -> Environment
Get the current environment
Returns the environment from AppConfig if initialized, otherwise detects from the APP_ENV environment variable.
Sourcepub fn is_production() -> bool
pub fn is_production() -> bool
Check if running in production environment
Sourcepub fn is_development() -> bool
pub fn is_development() -> bool
Check if running in development environment (local or development)