hcl

Function parse

Source
pub fn parse(input: &str) -> Result<Body>
Expand description

Parse a hcl::Body from a &str.

If deserialization into a different type is preferred consider using hcl::from_str.

§Example

use hcl::{Attribute, Block, Body};
let input = r#"
    some_attr = "foo"

    some_block "some_block_label" {
      attr = "value"
    }
"#;

let expected = Body::builder()
    .add_attribute(("some_attr", "foo"))
    .add_block(
        Block::builder("some_block")
            .add_label("some_block_label")
            .add_attribute(("attr", "value"))
            .build()
    )
    .build();

let body = hcl::parse(input)?;

assert_eq!(body, expected);

§Errors

This function fails with an error if the input cannot be parsed as HCL.