summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs11
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()