pub struct Config { /* private fields */ }Expand description
Application configuration loaded from TOML files.
Loads configuration with the following priority:
- Explicit path via
from_path() SWORD_CONFIG_PATHenvironment variableconfig/config.toml<executable_dir>/config/config.toml
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Result<Self, ConfigError>
pub fn new() -> Result<Self, ConfigError>
Loads configuration using default priority order.
§Errors
Returns ConfigError if no configuration file is found or contains invalid TOML.
Sourcepub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError>
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError>
Loads configuration from a specific file path without fallbacks.
§Errors
Returns ConfigError::FileNotFound if the file doesn’t exist.
Sourcepub fn get<T: DeserializeOwned + ConfigItem>(&self) -> Result<T, ConfigError>
pub fn get<T: DeserializeOwned + ConfigItem>(&self) -> Result<T, ConfigError>
Retrieves and deserializes a configuration section.
Type T must implement ConfigItem via #[config(key = "section")] macro.
Sourcepub fn get_or_panic<T: DeserializeOwned + ConfigItem>(&self) -> T
pub fn get_or_panic<T: DeserializeOwned + ConfigItem>(&self) -> T
Retrieves a configuration section, panicking if not found or invalid.
Sourcepub fn get_or_default<T: DeserializeOwned + ConfigItem + Default>(&self) -> T
pub fn get_or_default<T: DeserializeOwned + ConfigItem + Default>(&self) -> T
Retrieves a configuration section, returning default if not found or invalid.
Trait Implementations§
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
Mutably borrows from an owned value. Read more