pub struct Config { /* private fields */ }Available on crate feature
config only.Expand description
Implementations§
Source§impl Config
impl Config
Sourcepub fn parse<T: DeserializeOwned>(&self) -> Result<T, ConfigError>
pub fn parse<T: DeserializeOwned>(&self) -> Result<T, ConfigError>
Parse the configuration into a typed struct.
§Errors
Returns an error if the configuration cannot be parsed into the target type.
§Example
use commons::config::Config;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct MyConfig {
name: String,
}
let config = Config::new("name = \"test\"");
let parsed: MyConfig = config.parse().unwrap();
assert_eq!(parsed.name, "test");Sourcepub fn get<T: FromTomlValue>(&self, key: &str) -> Option<T>
pub fn get<T: FromTomlValue>(&self, key: &str) -> Option<T>
Get a value from the configuration by key path.
Supports nested keys using dot notation: “section.key”
§Example
use commons::config::Config;
let config = Config::new(r#"
[server]
port = 8080
"#);
let port: Option<i64> = config.get("server.port");
assert_eq!(port, Some(8080));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