Skip to main content

CONF

Struct CONF 

Source
pub struct CONF;
Expand description

Global configuration access point

Provides Total.js-style uniform configuration access using dot notation paths. This allows any part of the application to access configuration values without needing a Context or dependency injection.

Implementations§

Source§

impl CONF

Source

pub fn init(config: AppConfig) -> Result<()>

Initialize the global configuration

This should be called once during application startup, typically in the RustF application builder.

§Arguments
  • config - The application configuration to make globally available
§Examples
ⓘ
let config = AppConfig::load()?;
CONF::init(config)?;
Source

pub fn get<T: DeserializeOwned>(path: &str) -> Option<T>

Get a configuration value by dot-notation path

Returns the value at the specified path, or None if the path doesn’t exist. The type T must implement Deserialize.

§Arguments
  • path - Dot-separated path to the configuration value
§Examples
ⓘ
let port: Option<u16> = CONF::get("server.port");
let db_url: Option<String> = CONF::get("database.url");
Source

pub fn get_string(path: &str) -> Option<String>

Get a string configuration value

Convenience method for getting string values.

§Arguments
  • path - Dot-separated path to the configuration value
§Examples
ⓘ
let db_url = CONF::get_string("database.url");
let api_key = CONF::get_string("custom.api_key");
Source

pub fn get_int(path: &str) -> Option<i64>

Get an integer configuration value

Convenience method for getting integer values. Handles both i64 and u64 internally.

§Arguments
  • path - Dot-separated path to the configuration value
§Examples
ⓘ
let port = CONF::get_int("server.port").unwrap_or(8000);
let max_connections = CONF::get_int("server.max_connections");
Source

pub fn get_bool(path: &str) -> Option<bool>

Get a boolean configuration value

Convenience method for getting boolean values.

§Arguments
  • path - Dot-separated path to the configuration value
§Examples
ⓘ
let ssl_enabled = CONF::get_bool("server.ssl_enabled").unwrap_or(false);
let cache_enabled = CONF::get_bool("views.cache_enabled");
Source

pub fn get_float(path: &str) -> Option<f64>

Get a float configuration value

Convenience method for getting float values.

§Arguments
  • path - Dot-separated path to the configuration value
§Examples
ⓘ
let rate = CONF::get_float("custom.exchange_rate");
Source

pub fn get_or<T: DeserializeOwned>(path: &str, default: T) -> T

Get a configuration value with a default

Returns the value at the specified path, or the default if the path doesn’t exist.

§Arguments
  • path - Dot-separated path to the configuration value
  • default - Default value to return if path doesn’t exist
§Examples
ⓘ
let port = CONF::get_or("server.port", 8000);
let timeout = CONF::get_or("server.timeout", 30);
Source

pub fn has(path: &str) -> bool

Check if a configuration path exists

Returns true if the specified path exists in the configuration.

§Arguments
  • path - Dot-separated path to check
§Examples
ⓘ
if CONF::has("database.url") {
    // Database is configured
}
Source

pub fn all() -> Option<Arc<AppConfig>>

Get the entire configuration

Returns the full AppConfig. This is rarely needed as path-based access is preferred, but it’s available for cases where the typed config is required.

§Examples
ⓘ
let config = CONF::all();
let env = config.environment.as_str();
Source

pub fn env() -> Option<String>

Get the current environment

Convenience method to get the current environment.

§Examples
ⓘ
let env = CONF::env(); // "development", "production", etc.
Source

pub fn is_production() -> bool

Check if running in production

Convenience method to check if the application is in production mode.

§Examples
ⓘ
if CONF::is_production() {
    // Enable production optimizations
}
Source

pub fn is_development() -> bool

Check if running in development

Convenience method to check if the application is in development mode.

§Examples
ⓘ
if CONF::is_development() {
    // Enable development features
}
Source

pub fn is_initialized() -> bool

Check if configuration is initialized

Returns true if CONF::init() has been called successfully.

§Examples
ⓘ
if CONF::is_initialized() {
    let port = CONF::get_int("server.port");
}

Auto Trait Implementations§

§

impl Freeze for CONF

§

impl RefUnwindSafe for CONF

§

impl Send for CONF

§

impl Sync for CONF

§

impl Unpin for CONF

§

impl UnsafeUnpin for CONF

§

impl UnwindSafe for CONF

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more