pub fn to_value<T>(value: T) -> Result<Value>where
T: Serialize,
Expand description
Convert a T
into hcl::Value
which is an enum that can represent any valid HCL value.
§Example
use hcl::{Map, Value};
use serde::Serialize;
#[derive(Debug, Serialize)]
struct Custom {
foo: String,
bar: u64,
}
let custom = Custom {
foo: "baz".into(),
bar: 42,
};
let expected = Value::Object({
let mut object = Map::new();
object.insert("foo".into(), "baz".into());
object.insert("bar".into(), 42u64.into());
object
});
let value = hcl::to_value(&custom)?;
assert_eq!(value, expected);
§Errors
This conversion can fail if T
’s implementation of Serialize
decides to fail, or if T
contains a map with non-string keys.