diff options
author | XX <freecoder.xx@gmail.com> | 2018-04-06 15:53:03 +0300 |
---|---|---|
committer | XX <freecoder.xx@gmail.com> | 2018-04-06 15:53:03 +0300 |
commit | 86771ac343c8c95df61c48895c9d679391f1aff9 (patch) | |
tree | 06b4312eaecd8519eb94f761250f4990dc2fa4ea /src/config.rs | |
parent | e8fa9fee96185ddd18ebcef8a925c75459111edb (diff) |
Add config serialize ability
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/config.rs b/src/config.rs index 33d17bc..60f8551 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,11 +3,13 @@ use std::ops::Deref; use std::str::FromStr; use std::fmt::Debug; use serde::de::{Deserialize, Deserializer}; +use serde::ser::{Serialize, Serializer}; use error::*; use source::Source; +use ser::ConfigSerializer; -use value::{Value, ValueWithKey}; +use value::{Value, ValueKind, ValueWithKey}; use path; #[derive(Clone, Debug)] @@ -190,6 +192,13 @@ impl Config { T::deserialize(self) } + /// Attempt to deserialize the entire configuration into the requested type. + pub fn try_from<T: Serialize>(from: &T) -> Result<Self> { + let mut serializer = ConfigSerializer::default(); + from.serialize(&mut serializer)?; + Ok(serializer.output) + } + #[deprecated(since="0.7.0", note="please use 'try_into' instead")] pub fn deserialize<'de, T: Deserialize<'de>>(self) -> Result<T> { self.try_into() |