Struct hcl::structure::BlockBuilder
source · 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) -> BlockBuilderwhere
I: IntoIterator,
I::Item: Into<BlockLabel>,
pub fn add_labels<I>(self, iter: I) -> BlockBuilderwhere I: IntoIterator, I::Item: Into<BlockLabel>,
Adds BlockLabel
s from an iterator.
Consumes self
and returns a new BlockBuilder
.
sourcepub fn add_attribute<A>(self, attr: A) -> BlockBuilderwhere
A: Into<Attribute>,
pub fn add_attribute<A>(self, attr: A) -> BlockBuilderwhere A: Into<Attribute>,
Adds an Attribute
to the block body.
Consumes self
and returns a new BlockBuilder
.
sourcepub fn add_attributes<I>(self, iter: I) -> BlockBuilderwhere
I: IntoIterator,
I::Item: Into<Attribute>,
pub fn add_attributes<I>(self, iter: I) -> BlockBuilderwhere I: IntoIterator, I::Item: Into<Attribute>,
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) -> BlockBuilderwhere
B: Into<Block>,
pub fn add_block<B>(self, block: B) -> BlockBuilderwhere B: Into<Block>,
Adds another Block
to the block body.
Consumes self
and returns a new BlockBuilder
.
sourcepub fn add_blocks<I>(self, iter: I) -> BlockBuilderwhere
I: IntoIterator,
I::Item: Into<Block>,
pub fn add_blocks<I>(self, iter: I) -> BlockBuilderwhere I: IntoIterator, I::Item: Into<Block>,
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) -> BlockBuilderwhere
S: Into<Structure>,
pub fn add_structure<S>(self, structure: S) -> BlockBuilderwhere S: Into<Structure>,
Adds a Structure
to the block body.
Consumes self
and returns a new BlockBuilder
.
sourcepub fn add_structures<I>(self, iter: I) -> BlockBuilderwhere
I: IntoIterator,
I::Item: Into<Structure>,
pub fn add_structures<I>(self, iter: I) -> BlockBuilderwhere I: IntoIterator, I::Item: Into<Structure>,
Adds Structure
s to the block body from an iterator.
Consumes self
and returns a new BlockBuilder
.