mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-09-11 03:05:58 +03:00
Config can now be serialized / deserialized
This commit is contained in:
41
src/util.rs
41
src/util.rs
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user