pub struct BlockBuilder { /* private fields */ }
Expand description
BlockBuilder
builds an HCL Block
.
The builder allows to build the Block
by adding labels, attributes and other nested blocks
via chained method calls. A call to .build()
produces the final
Block
.
§Example
use hcl_edit::structure::{Attribute, Block, Body};
use hcl_edit::Ident;
let block = Block::builder(Ident::new("resource"))
.labels(["aws_s3_bucket", "mybucket"])
.attribute(Attribute::new(Ident::new("name"), "mybucket"))
.block(
Block::builder(Ident::new("logging"))
.attribute(Attribute::new(Ident::new("target_bucket"), "mylogsbucket"))
)
.build();
Implementations§
Source§impl BlockBuilder
impl BlockBuilder
Sourcepub fn label(self, label: impl Into<BlockLabel>) -> Self
pub fn label(self, label: impl Into<BlockLabel>) -> Self
Adds a BlockLabel
.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn labels<I>(self, iter: I) -> BlockBuilder
pub fn labels<I>(self, iter: I) -> BlockBuilder
Adds BlockLabel
s from an iterator.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn attribute(self, attr: impl Into<Attribute>) -> BlockBuilder
pub fn attribute(self, attr: impl Into<Attribute>) -> BlockBuilder
Adds an Attribute
to the block body.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn attributes<I>(self, iter: I) -> BlockBuilder
pub fn attributes<I>(self, iter: I) -> BlockBuilder
Adds Attribute
s to the block body from an iterator.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn block(self, block: impl Into<Block>) -> BlockBuilder
pub fn block(self, block: impl Into<Block>) -> BlockBuilder
Adds another Block
to the block body.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn blocks<I>(self, iter: I) -> BlockBuilder
pub fn blocks<I>(self, iter: I) -> BlockBuilder
Adds Block
s to the block body from an iterator.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn structure(self, structures: impl Into<Structure>) -> BlockBuilder
pub fn structure(self, structures: impl Into<Structure>) -> BlockBuilder
Adds a Structure
to the block body.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn structures<I>(self, iter: I) -> BlockBuilder
pub fn structures<I>(self, iter: I) -> BlockBuilder
Adds Structure
s to the block body from an iterator.
Consumes self
and returns a new BlockBuilder
.