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::Block;
let block = Block::builder("resource")
.add_label("aws_s3_bucket")
.add_label("mybucket")
.add_attribute(("name", "mybucket"))
.add_block(
Block::builder("logging")
.add_attribute(("target_bucket", "mylogsbucket"))
.build()
)
.build();
Implementations§
Source§impl BlockBuilder
impl BlockBuilder
Sourcepub fn new<I>(identifier: I) -> BlockBuilderwhere
I: Into<Identifier>,
pub fn new<I>(identifier: I) -> BlockBuilderwhere
I: Into<Identifier>,
Creates a new BlockBuilder
to start building a new Block
with the provided
identifier.
Sourcepub fn add_label<L>(self, label: L) -> BlockBuilderwhere
L: Into<BlockLabel>,
pub fn add_label<L>(self, label: L) -> BlockBuilderwhere
L: Into<BlockLabel>,
Adds a BlockLabel
.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn add_labels<I>(self, iter: I) -> BlockBuilder
pub fn add_labels<I>(self, iter: I) -> BlockBuilder
Adds BlockLabel
s from an iterator.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn add_attribute<A>(self, attr: A) -> BlockBuilder
pub fn add_attribute<A>(self, attr: A) -> BlockBuilder
Adds an Attribute
to the block body.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn add_attributes<I>(self, iter: I) -> BlockBuilder
pub fn add_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 add_block<B>(self, block: B) -> BlockBuilder
pub fn add_block<B>(self, block: B) -> BlockBuilder
Adds another Block
to the block body.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn add_blocks<I>(self, iter: I) -> BlockBuilder
pub fn add_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 add_structure<S>(self, structure: S) -> BlockBuilder
pub fn add_structure<S>(self, structure: S) -> BlockBuilder
Adds a Structure
to the block body.
Consumes self
and returns a new BlockBuilder
.
Sourcepub fn add_structures<I>(self, iter: I) -> BlockBuilder
pub fn add_structures<I>(self, iter: I) -> BlockBuilder
Adds Structure
s to the block body from an iterator.
Consumes self
and returns a new BlockBuilder
.