Config can now be serialized / deserialized

This commit is contained in:
Daniel García
2019-02-02 01:09:21 +01:00
parent 20d8d800f3
commit 86ed75bf7c
8 changed files with 207 additions and 261 deletions

View File

@@ -140,18 +140,6 @@ where
}
}
pub fn try_parse_string_or<S, T, U>(string: impl Try<Ok = S, Error = U>, default: T) -> T
where
S: AsRef<str>,
T: FromStr,
{
if let Ok(Ok(value)) = string.into_result().map(|s| s.as_ref().parse::<T>()) {
value
} else {
default
}
}
//
// Env methods
//
@@ -165,13 +153,6 @@ where
try_parse_string(env::var(key))
}
pub fn get_env_or<V>(key: &str, default: V) -> V
where
V: FromStr,
{
try_parse_string_or(env::var(key), default)
}
//
// Date util methods
//
@@ -303,3 +284,25 @@ where
}
}
}
//
// Into Result
//
use crate::error::Error;
pub trait IntoResult<T> {
fn into_result(self) -> Result<T, Error>;
}
impl<T> IntoResult<T> for Result<T, Error> {
fn into_result(self) -> Result<T, Error> {
self
}
}
impl<T> IntoResult<T> for T {
fn into_result(self) -> Result<T, Error> {
Ok(self)
}
}