Added From trait to Settings

This commit is contained in:
Lucien Cartier-Tilet 2020-03-27 23:25:16 +01:00
parent 8642067eb3
commit e00f489f55
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -178,6 +178,28 @@ impl PartialEq for Settings {
} }
} }
impl<S> From<S> for Settings
where
S: ToString,
{
/// Import settings from file path described by the argument `source`
///
/// # Arguments
///
/// * `source` - path to the file from which settings should be imported
///
/// # Example
///
/// ```no_run
/// let s = lang_evolve_core::settings::Settings::from("settings.yml");
/// ```
fn from(source: S) -> Self {
let source = source.to_string();
let path = std::path::Path::new(&source);
Settings::import(&path).unwrap()
}
}
impl Eq for Settings {} impl Eq for Settings {}
#[test] #[test]