pub fn from_str<'de, T>(s: &'de str) -> Result<T>where
T: Deserialize<'de>,
Expand description
Deserialize an instance of type T
from a string of HCL text.
By default, the deserialization will follow the HCL JSON Specification.
If preserving HCL semantics is required consider deserializing into a Body
instead or
use hcl::parse
to directly parse the input into a Body
.
§Example
use serde_json::{json, Value};
let input = r#"
some_attr = {
foo = [1, 2]
bar = true
}
some_block "some_block_label" {
attr = "value"
}
"#;
let expected = json!({
"some_attr": {
"foo": [1, 2],
"bar": true
},
"some_block": {
"some_block_label": {
"attr": "value"
}
}
});
let value: Value = hcl::from_str(input)?;
assert_eq!(value, expected);
§Errors
This functions fails with an error if the data does not match the structure of T
.