pub fn from_body<T>(body: Body) -> Result<T>where
T: DeserializeOwned,
Expand description
Interpret a hcl::Body
as an instance of type T
.
§Example
use serde::Deserialize;
use hcl::{Block, Body};
#[derive(Deserialize, Debug)]
struct User {
name: String,
email: String,
}
#[derive(Deserialize, Debug)]
struct Config {
user: User,
}
let body = Body::builder()
.add_block(
Block::builder("user")
.add_attribute(("name", "John Doe"))
.add_attribute(("email", "john@doe.tld"))
.build()
)
.build();
let config: Config = hcl::from_body(body)?;
println!("{:#?}", config);
§Errors
This functions fails with an error if the data does not match the structure of T
.