From e00f489f552b90310ee32680bb878f320a84847d Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Fri, 27 Mar 2020 23:25:16 +0100 Subject: [PATCH] Added From trait to Settings --- src/settings/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 95a405b..13f23df 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -178,6 +178,28 @@ impl PartialEq for Settings { } } +impl From 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 {} #[test]