Expand description
Format data structures as HCL.
This module provides the Formatter
type and the convienince functions to_string
,
to_vec
and to_writer
for formatting the data structures provided by this crate as HCL.
For serialization of other Rust data structures implementing serde::Serialize
refer to the
documentation of the ser
module.
§Examples
Format an HCL block as string:
let block = hcl::Block::builder("user")
.add_label("johndoe")
.add_attribute(("age", 34))
.add_attribute(("email", "johndoe@example.com"))
.build();
let expected = r#"
user "johndoe" {
age = 34
email = "johndoe@example.com"
}
"#.trim_start();
let formatted = hcl::format::to_string(&block)?;
assert_eq!(formatted, expected);
Structs§
- A pretty printing HCL formatter.
- A builder to create a
Formatter
.
Traits§
- A trait to format data structures as HCL.
Functions§
- Format the given value as an HCL string.
- Format the given value as an HCL byte vector.
- Format the given value as HCL into the IO stream.