Struct hcl_edit::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_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) -> BlockBuilderwhere
I: IntoIterator,
I::Item: Into<BlockLabel>,
pub fn labels<I>(self, iter: I) -> BlockBuilderwhere I: IntoIterator, I::Item: Into<BlockLabel>,
Adds BlockLabels 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) -> BlockBuilderwhere
I: IntoIterator,
I::Item: Into<Attribute>,
pub fn attributes<I>(self, iter: I) -> BlockBuilderwhere I: IntoIterator, I::Item: Into<Attribute>,
Adds Attributes 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) -> BlockBuilderwhere
I: IntoIterator,
I::Item: Into<Block>,
pub fn blocks<I>(self, iter: I) -> BlockBuilderwhere I: IntoIterator, I::Item: Into<Block>,
Adds Blocks 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) -> BlockBuilderwhere
I: IntoIterator,
I::Item: Into<Structure>,
pub fn structures<I>(self, iter: I) -> BlockBuilderwhere I: IntoIterator, I::Item: Into<Structure>,
Adds Structures to the block body from an iterator.
Consumes self and returns a new BlockBuilder.