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 ferro_rs::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 ferro_rs::{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 ferro_rs::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)
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more