pub struct Config { /* private fields */ }Expand description
A read-only view of the application’s configuration. Cheap to clone.
Implementations§
Source§impl Config
impl Config
pub fn new() -> Self
Sourcepub fn from_pairs<K, V>(pairs: impl IntoIterator<Item = (K, V)>) -> Self
pub fn from_pairs<K, V>(pairs: impl IntoIterator<Item = (K, V)>) -> Self
Build from explicit pairs. Chiefly useful in tests.
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Self>
pub fn load(path: impl AsRef<Path>) -> Result<Self>
luxid.toml with the environment layered over it.
A missing file is not an error: an application configured entirely by environment is a perfectly ordinary one, and failing here would make the file mandatory for no reason.
pub fn has(&self, key: &str) -> bool
pub fn keys(&self) -> impl Iterator<Item = &str>
pub fn is_empty(&self) -> bool
Sourcepub fn get<T: DeserializeOwned>(&self, key: &str) -> Result<T>
pub fn get<T: DeserializeOwned>(&self, key: &str) -> Result<T>
A required value, decoded into T.
Sourcepub fn try_get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
pub fn try_get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
An optional value, decoded into T.
Sourcepub fn get_or<T: DeserializeOwned>(&self, key: &str, default: T) -> Result<T>
pub fn get_or<T: DeserializeOwned>(&self, key: &str, default: T) -> Result<T>
A value with a fallback. A malformed value still fails — silently falling back would hide a typo in production.
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