pub fn from_value<T>(value: Value) -> Result<T>where
T: DeserializeOwned,
Expand description
Convert a hcl::Value
into a type T
that implements serde::Deserialize
.
§Example
use hcl::{Map, Value};
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct Custom {
foo: String,
bar: u64,
}
let value = Value::Object({
let mut object = Map::new();
object.insert("foo".into(), "baz".into());
object.insert("bar".into(), 42u64.into());
object
});
let expected = Custom {
foo: "baz".into(),
bar: 42,
};
let custom: Custom = hcl::from_value(value)?;
assert_eq!(custom, expected);
§Errors
This conversion can fail if T
’s implementation of serde::Deserialize
decides to fail.