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

source

pub fn new<I>(identifier: I) -> BlockBuilder
where I: Into<Identifier>,

Creates a new BlockBuilder to start building a new Block with the provided identifier.

source

pub fn add_label<L>(self, label: L) -> BlockBuilder
where L: Into<BlockLabel>,

Adds a BlockLabel.

Consumes self and returns a new BlockBuilder.

source

pub fn add_labels<I>(self, iter: I) -> BlockBuilder

Adds BlockLabels from an iterator.

Consumes self and returns a new BlockBuilder.

source

pub fn add_attribute<A>(self, attr: A) -> BlockBuilder
where A: Into<Attribute>,

Adds an Attribute to the block body.

Consumes self and returns a new BlockBuilder.

source

pub fn add_attributes<I>(self, iter: I) -> BlockBuilder

Adds Attributes to the block body from an iterator.

Consumes self and returns a new BlockBuilder.

source

pub fn add_block<B>(self, block: B) -> BlockBuilder
where B: Into<Block>,

Adds another Block to the block body.

Consumes self and returns a new BlockBuilder.

source

pub fn add_blocks<I>(self, iter: I) -> BlockBuilder
where I: IntoIterator, I::Item: Into<Block>,

Adds Blocks to the block body from an iterator.

Consumes self and returns a new BlockBuilder.

source

pub fn add_structure<S>(self, structure: S) -> BlockBuilder
where S: Into<Structure>,

Adds a Structure to the block body.

Consumes self and returns a new BlockBuilder.

source

pub fn add_structures<I>(self, iter: I) -> BlockBuilder

Adds Structures to the block body from an iterator.

Consumes self and returns a new BlockBuilder.

source

pub fn build(self) -> Block

Consumes self and builds the Block from the items added via the builder methods.

Trait Implementations§

source§

impl Debug for BlockBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.