summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/glob/src/main.rs6
-rw-r--r--examples/hierarchical-env/src/settings.rs2
-rw-r--r--examples/simple/src/main.rs2
-rw-r--r--examples/watch/src/main.rs2
-rw-r--r--src/config.rs8
-rw-r--r--src/ser.rs4
-rw-r--r--src/value.rs14
-rw-r--r--tests/defaults.rs6
-rw-r--r--tests/empty.rs4
-rw-r--r--tests/errors.rs10
-rw-r--r--tests/file_hjson.rs2
-rw-r--r--tests/file_ini.rs2
-rw-r--r--tests/file_json.rs2
-rw-r--r--tests/file_toml.rs2
-rw-r--r--tests/file_yaml.rs2
-rw-r--r--tests/get.rs12
16 files changed, 41 insertions, 39 deletions
diff --git a/examples/glob/src/main.rs b/examples/glob/src/main.rs
index e653b77..206ce2e 100644
--- a/examples/glob/src/main.rs
+++ b/examples/glob/src/main.rs
@@ -19,7 +19,7 @@ fn main() {
// Print out our settings (as a HashMap)
println!("\n{:?} \n\n-----------",
- settings.try_into::<HashMap<String, String>>().unwrap());
+ settings.try_deserialize::<HashMap<String, String>>().unwrap());
// Option 2
// --------
@@ -33,7 +33,7 @@ fn main() {
// Print out our settings (as a HashMap)
println!("\n{:?} \n\n-----------",
- settings.try_into::<HashMap<String, String>>().unwrap());
+ settings.try_deserialize::<HashMap<String, String>>().unwrap());
// Option 3
// --------
@@ -48,5 +48,5 @@ fn main() {
// Print out our settings (as a HashMap)
println!("\n{:?} \n\n-----------",
- settings.try_into::<HashMap<String, String>>().unwrap());
+ settings.try_deserialize::<HashMap<String, String>>().unwrap());
}
diff --git a/examples/hierarchical-env/src/settings.rs b/examples/hierarchical-env/src/settings.rs
index a341a21..353053e 100644
--- a/examples/hierarchical-env/src/settings.rs
+++ b/examples/hierarchical-env/src/settings.rs
@@ -65,6 +65,6 @@ impl Settings {
println!("database: {:?}", s.get::<String>("database.url"));
// You can deserialize (and thus freeze) the entire configuration as
- s.try_into()
+ s.try_deserialize()
}
}
diff --git a/examples/simple/src/main.rs b/examples/simple/src/main.rs
index 1a4fcd4..e4e5475 100644
--- a/examples/simple/src/main.rs
+++ b/examples/simple/src/main.rs
@@ -13,5 +13,5 @@ fn main() {
// Print out our settings (as a HashMap)
println!("{:?}",
- settings.try_into::<HashMap<String, String>>().unwrap());
+ settings.try_deserialize::<HashMap<String, String>>().unwrap());
}
diff --git a/examples/watch/src/main.rs b/examples/watch/src/main.rs
index 91391e0..86f1bc6 100644
--- a/examples/watch/src/main.rs
+++ b/examples/watch/src/main.rs
@@ -26,7 +26,7 @@ fn show() {
.read()
.unwrap()
.clone()
- .try_into::<HashMap<String, String>>()
+ .try_deserialize::<HashMap<String, String>>()
.unwrap());
}
diff --git a/src/config.rs b/src/config.rs
index 1019061..99216ad 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -227,20 +227,20 @@ impl Config {
}
/// Attempt to deserialize the entire configuration into the requested type.
- pub fn try_into<'de, T: Deserialize<'de>>(self) -> Result<T> {
+ pub fn try_deserialize<'de, T: Deserialize<'de>>(self) -> Result<T> {
T::deserialize(self)
}
/// Attempt to serialize the entire configuration from the given type.
- pub fn try_from<T: Serialize>(from: &T) -> Result<Self> {
+ pub fn try_serialize<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")]
+ #[deprecated(since = "0.7.0", note = "please use 'try_deserialize' instead")]
pub fn deserialize<'de, T: Deserialize<'de>>(self) -> Result<T> {
- self.try_into()
+ self.try_deserialize()
}
}
diff --git a/src/ser.rs b/src/ser.rs
index 39c02b9..ce016bf 100644
--- a/src/ser.rs
+++ b/src/ser.rs
@@ -710,9 +710,9 @@ mod test {
int: 1,
seq: vec!["a".to_string(), "b".to_string()],
};
- let config = Config::try_from(&test).unwrap();
+ let config = Config::try_serialize(&test).unwrap();
- let actual: Test = config.try_into().unwrap();
+ let actual: Test = config.try_deserialize().unwrap();
assert_eq!(test, actual);
}
}
diff --git a/src/value.rs b/src/value.rs
index 177acf7..700279b 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -151,12 +151,12 @@ impl Value {
}
/// Attempt to deserialize this value into the requested type.
- pub fn try_into<'de, T: Deserialize<'de>>(self) -> Result<T> {
+ pub fn try_deserialize<'de, T: Deserialize<'de>>(self) -> Result<T> {
T::deserialize(self)
}
/// Returns `self` as a bool, if possible.
- // FIXME: Should this not be `try_into_*` ?
+ // FIXME: Should this not be `try_deserialize_*` ?
pub fn into_bool(self) -> Result<bool> {
match self.kind {
ValueKind::Boolean(value) => Ok(value),
@@ -197,7 +197,7 @@ impl Value {
}
/// Returns `self` into an i64, if possible.
- // FIXME: Should this not be `try_into_*` ?
+ // FIXME: Should this not be `try_deserialize_*` ?
pub fn into_int(self) -> Result<i64> {
match self.kind {
ValueKind::Integer(value) => Ok(value),
@@ -242,7 +242,7 @@ impl Value {
}
/// Returns `self` into a f64, if possible.
- // FIXME: Should this not be `try_into_*` ?
+ // FIXME: Should this not be `try_deserialize_*` ?
pub fn into_float(self) -> Result<f64> {
match self.kind {
ValueKind::Float(value) => Ok(value),
@@ -287,7 +287,7 @@ impl Value {
}
/// Returns `self` into a str, if possible.
- // FIXME: Should this not be `try_into_*` ?
+ // FIXME: Should this not be `try_deserialize_*` ?
pub fn into_str(self) -> Result<String> {
match self.kind {
ValueKind::String(value) => Ok(value),
@@ -316,7 +316,7 @@ impl Value {
}
/// Returns `self` into an array, if possible
- // FIXME: Should this not be `try_into_*` ?
+ // FIXME: Should this not be `try_deserialize_*` ?
pub fn into_array(self) -> Result<Vec<Value>> {
match self.kind {
ValueKind::Array(value) => Ok(value),
@@ -356,7 +356,7 @@ impl Value {
}
/// If the `Value` is a Table, returns the associated Map.
- // FIXME: Should this not be `try_into_*` ?
+ // FIXME: Should this not be `try_deserialize_*` ?
pub fn into_table(self) -> Result<HashMap<String, Value>> {
match self.kind {
ValueKind::Table(value) => Ok(value),
diff --git a/tests/defaults.rs b/tests/defaults.rs
index c50dd65..779dfdd 100644
--- a/tests/defaults.rs
+++ b/tests/defaults.rs
@@ -22,14 +22,14 @@ impl Default for Settings {
#[test]
fn set_defaults() {
let c = Config::new();
- let s: Settings = c.try_into().expect("Deserialization failed");
+ let s: Settings = c.try_deserialize().expect("Deserialization failed");
assert_eq!(s.db_host, "default");
}
#[test]
fn try_from_defaults() {
- let c = Config::try_from(&Settings::default()).expect("Serialization failed");
- let s: Settings = c.try_into().expect("Deserialization failed");
+ let c = Config::try_serialize(&Settings::default()).expect("Serialization failed");
+ let s: Settings = c.try_deserialize().expect("Deserialization failed");
assert_eq!(s.db_host, "default");
}
diff --git a/tests/empty.rs b/tests/empty.rs
index 92d3384..57a592e 100644
--- a/tests/empty.rs
+++ b/tests/empty.rs
@@ -15,7 +15,9 @@ struct Settings {
#[test]
fn empty_deserializes() {
- let s: Settings = Config::new().try_into().expect("Deserialization failed");
+ let s: Settings = Config::new()
+ .try_deserialize()
+ .expect("Deserialization failed");
assert_eq!(s.foo, 0);
assert_eq!(s.bar, 0);
}
diff --git a/tests/errors.rs b/tests/errors.rs
index ec96c98..04f11fe 100644
--- a/tests/errors.rs
+++ b/tests/errors.rs
@@ -56,7 +56,7 @@ fn test_error_type_detached() {
let c = make();
let value = c.get::<Value>("boolean_s_parse").unwrap();
- let res = value.try_into::<bool>();
+ let res = value.try_deserialize::<bool>();
assert!(res.is_err());
assert_eq!(
@@ -76,14 +76,14 @@ fn test_error_enum_de() {
}
let on_v: Value = "on".into();
- let on_d = on_v.try_into::<Diode>();
+ let on_d = on_v.try_deserialize::<Diode>();
assert_eq!(
on_d.unwrap_err().to_string(),
"enum Diode does not have variant constructor on".to_string()
);
let array_v: Value = vec![100, 100].into();
- let array_d = array_v.try_into::<Diode>();
+ let array_d = array_v.try_deserialize::<Diode>();
assert_eq!(
array_d.unwrap_err().to_string(),
"value of enum Diode should be represented by either string or table with exactly one key"
@@ -97,7 +97,7 @@ fn test_error_enum_de() {
.cloned()
.collect::<std::collections::HashMap<String, Value>>()
.into();
- let confused_d = confused_v.try_into::<Diode>();
+ let confused_d = confused_v.try_deserialize::<Diode>();
assert_eq!(
confused_d.unwrap_err().to_string(),
"value of enum Diode should be represented by either string or table with exactly one key"
@@ -122,7 +122,7 @@ inner:
let mut cfg = Config::new();
cfg.merge(File::from_str(CFG, FileFormat::Yaml)).unwrap();
- let e = cfg.try_into::<Outer>().unwrap_err();
+ let e = cfg.try_deserialize::<Outer>().unwrap_err();
if let ConfigError::Type {
key: Some(path), ..
} = e
diff --git a/tests/file_hjson.rs b/tests/file_hjson.rs
index b866dd6..c5e07fb 100644
--- a/tests/file_hjson.rs
+++ b/tests/file_hjson.rs
@@ -46,7 +46,7 @@ fn test_file() {
let c = make();
// Deserialize the entire file as single struct
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert!(s.debug.approx_eq_ulps(&1.0, 2));
assert_eq!(s.production, Some("false".to_string()));
diff --git a/tests/file_ini.rs b/tests/file_ini.rs
index e473158..7df9d38 100644
--- a/tests/file_ini.rs
+++ b/tests/file_ini.rs
@@ -36,7 +36,7 @@ fn make() -> Config {
#[test]
fn test_file() {
let c = make();
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert_eq!(
s,
Settings {
diff --git a/tests/file_json.rs b/tests/file_json.rs
index 0dfeffe..d5e9be2 100644
--- a/tests/file_json.rs
+++ b/tests/file_json.rs
@@ -46,7 +46,7 @@ fn test_file() {
let c = make();
// Deserialize the entire file as single struct
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert!(s.debug.approx_eq_ulps(&1.0, 2));
assert_eq!(s.production, Some("false".to_string()));
diff --git a/tests/file_toml.rs b/tests/file_toml.rs
index 7591c20..9b4ef65 100644
--- a/tests/file_toml.rs
+++ b/tests/file_toml.rs
@@ -54,7 +54,7 @@ fn test_file() {
let c = make();
// Deserialize the entire file as single struct
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert!(s.debug.approx_eq_ulps(&1.0, 2));
assert_eq!(s.production, Some("false".to_string()));
diff --git a/tests/file_yaml.rs b/tests/file_yaml.rs
index 41b495c..8709019 100644
--- a/tests/file_yaml.rs
+++ b/tests/file_yaml.rs
@@ -46,7 +46,7 @@ fn test_file() {
let c = make();
// Deserialize the entire file as single struct
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert!(s.debug.approx_eq_ulps(&1.0, 2));
assert_eq!(s.production, Some("false".to_string()));
diff --git a/tests/get.rs b/tests/get.rs
index 135d3b0..a8a97d2 100644
--- a/tests/get.rs
+++ b/tests/get.rs
@@ -134,7 +134,7 @@ fn test_map_struct() {
}
let c = make();
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert_eq!(s.place.len(), 8);
assert_eq!(
@@ -149,7 +149,7 @@ fn test_file_struct() {
let c = make();
// Deserialize the entire file as single struct
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert!(s.debug.approx_eq_ulps(&1.0, 2));
assert_eq!(s.production, Some("false".to_string()));
@@ -197,7 +197,7 @@ fn test_struct_array() {
}
let c = make();
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert_eq!(s.elements.len(), 10);
assert_eq!(s.elements[3], "4".to_string());
@@ -219,7 +219,7 @@ fn test_enum() {
}
let c = make();
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert_eq!(s.diodes["green"], Diode::Off);
assert_eq!(s.diodes["red"], Diode::Brightness(100));
@@ -254,7 +254,7 @@ fn test_enum_key() {
}
let c = make();
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert_eq!(s.proton[&Quark::Up], 2);
assert_eq!(s.quarks.len(), 6);
@@ -268,7 +268,7 @@ fn test_int_key() {
}
let c = make();
- let s: Settings = c.try_into().unwrap();
+ let s: Settings = c.try_deserialize().unwrap();
assert_eq!(s.divisors[&4], 3);
assert_eq!(s.divisors.len(), 4);
}