hcl

Struct Body

Source
pub struct Body(pub Vec<Structure>);
Expand description

Represents an HCL config file body.

A Body consists of zero or more Attribute and Block HCL structures.

Tuple Fields§

§0: Vec<Structure>

Implementations§

Source§

impl Body

Source

pub fn into_inner(self) -> Vec<Structure>

Consumes self and returns the wrapped Vec<Structure>.

Source

pub fn builder() -> BodyBuilder

Creates a new BodyBuilder to start building a new Body.

Source

pub fn iter(&self) -> Iter<'_>

An iterator visiting all structures within the Body. The iterator element type is &'a Structure.

§Examples
use hcl::{Attribute, Body};

let body = Body::from([
    Attribute::new("a", 1),
    Attribute::new("b", 2),
    Attribute::new("c", 3),
]);

for structure in body.iter() {
    println!("{structure:?}");
}
Source

pub fn iter_mut(&mut self) -> IterMut<'_>

An iterator visiting all structures within the Body. The iterator element type is &'a mut Structure.

§Examples
use hcl::{Attribute, Block, Body, Identifier, Structure};

let mut body = Body::from([
    Structure::Attribute(Attribute::new("a", 1)),
    Structure::Block(Block::new("b")),
    Structure::Attribute(Attribute::new("c", 3)),
]);

// Update all attribute keys and block identifiers
for structure in body.iter_mut() {
    match structure {
        Structure::Attribute(attr) => {
            attr.key = Identifier::new(format!("attr_{}", attr.key)).unwrap();
        }
        Structure::Block(block) => {
            block.identifier = Identifier::new(format!("block_{}", block.identifier)).unwrap();
        }
    }
}

assert_eq!(body.into_inner(), [
    Structure::Attribute(Attribute::new("attr_a", 1)),
    Structure::Block(Block::new("block_b")),
    Structure::Attribute(Attribute::new("attr_c", 3)),
]);
Source

pub fn attributes(&self) -> Attributes<'_>

An iterator visiting all attributes within the Body. The iterator element type is &'a Attribute.

§Examples
use hcl::{Attribute, Block, Body, Structure};

let body = Body::from([
    Structure::Attribute(Attribute::new("a", 1)),
    Structure::Block(Block::new("b")),
    Structure::Attribute(Attribute::new("c", 3)),
]);

let vec: Vec<&Attribute> = body.attributes().collect();
assert_eq!(vec, [&Attribute::new("a", 1), &Attribute::new("c", 3)]);
Source

pub fn attributes_mut(&mut self) -> AttributesMut<'_>

An iterator visiting all attributes within the Body. The iterator element type is &'a mut Attribute.

§Examples
use hcl::{Attribute, Block, Body, Identifier, Structure};

let mut body = Body::from([
    Structure::Attribute(Attribute::new("a", 1)),
    Structure::Block(Block::new("b")),
    Structure::Attribute(Attribute::new("c", 3)),
]);

// Update all attribute keys
for attr in body.attributes_mut() {
    attr.key = Identifier::new(format!("attr_{}", attr.key)).unwrap();
}

assert_eq!(body.into_inner(), [
    Structure::Attribute(Attribute::new("attr_a", 1)),
    Structure::Block(Block::new("b")),
    Structure::Attribute(Attribute::new("attr_c", 3)),
]);
Source

pub fn into_attributes(self) -> IntoAttributes

Creates a consuming iterator visiting all attributes within the Body. The object cannot be used after calling this. The iterator element type is Attribute.

§Examples
use hcl::{Attribute, Block, Body, Structure};

let body = Body::from([
    Structure::Attribute(Attribute::new("a", 1)),
    Structure::Block(Block::new("b")),
    Structure::Attribute(Attribute::new("c", 3)),
]);

let vec: Vec<Attribute> = body.into_attributes().collect();
assert_eq!(vec, [Attribute::new("a", 1), Attribute::new("c", 3)]);
Source

pub fn blocks(&self) -> Blocks<'_>

An iterator visiting all blocks within the Body. The iterator element type is &'a Block.

§Examples
use hcl::{Attribute, Block, Body, Structure};

let body = Body::from([
    Structure::Attribute(Attribute::new("a", 1)),
    Structure::Block(Block::new("b")),
    Structure::Attribute(Attribute::new("c", 3)),
]);

let vec: Vec<&Block> = body.blocks().collect();
assert_eq!(vec, [&Block::new("b")]);
Source

pub fn blocks_mut(&mut self) -> BlocksMut<'_>

An iterator visiting all blocks within the Body. The iterator element type is &'a mut Block.

§Examples
use hcl::{Attribute, Block, Body, Identifier, Structure};

let mut body = Body::from([
    Structure::Attribute(Attribute::new("a", 1)),
    Structure::Block(Block::new("b")),
    Structure::Attribute(Attribute::new("c", 3)),
]);

// Update all block identifiers
for block in body.blocks_mut() {
    block.identifier = Identifier::new(format!("block_{}", block.identifier)).unwrap();
}

assert_eq!(body.into_inner(), [
    Structure::Attribute(Attribute::new("a", 1)),
    Structure::Block(Block::new("block_b")),
    Structure::Attribute(Attribute::new("c", 3)),
]);
Source

pub fn into_blocks(self) -> IntoBlocks

Creates a consuming iterator visiting all blocks within the Body. The object cannot be used after calling this. The iterator element type is Block.

§Examples
use hcl::{Attribute, Block, Body, Structure};

let body = Body::from([
    Structure::Attribute(Attribute::new("a", 1)),
    Structure::Block(Block::new("b")),
    Structure::Attribute(Attribute::new("c", 3)),
]);

let vec: Vec<Block> = body.into_blocks().collect();
assert_eq!(vec, [Block::new("b")]);

Trait Implementations§

Source§

impl Clone for Body

Source§

fn clone(&self) -> Body

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Body

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Body

Source§

fn default() -> Body

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Body

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Evaluate for Body

Source§

type Output = Body

The type that is returned by evaluate on success.
Source§

fn evaluate(&self, ctx: &Context<'_>) -> EvalResult<Self::Output>

Recursively evaluates all HCL templates and expressions in the implementing type using the variables and functions declared in the Context. Read more
Source§

fn evaluate_in_place(&mut self, ctx: &Context<'_>) -> EvalResult<(), Errors>

Recursively tries to evaluate all nested expressions in place. Read more
Source§

impl<T> Extend<T> for Body
where T: Into<Structure>,

Source§

fn extend<I>(&mut self, iterable: I)
where I: IntoIterator<Item = T>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Format for Body

Source§

fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>
where W: Write,

Formats a HCL structure using a formatter and writes the result to the provided writer. Read more
Source§

fn format_vec<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<Vec<u8>>
where W: Write + AsMut<Vec<u8>>,

Formats a HCL structure using a formatter and returns the result as a Vec<u8>. Read more
Source§

fn format_string<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<String>
where W: Write + AsMut<Vec<u8>>,

Formats a HCL structure using a formatter and returns the result as a String. Read more
Source§

impl<T> From<&[T]> for Body
where T: Clone + Into<Structure>,

Source§

fn from(slice: &[T]) -> Self

Converts to this type from the input type.
Source§

impl<T> From<&mut [T]> for Body
where T: Clone + Into<Structure>,

Source§

fn from(slice: &mut [T]) -> Self

Converts to this type from the input type.
Source§

impl<T, const N: usize> From<[T; N]> for Body
where T: Into<Structure>,

Source§

fn from(arr: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl From<Body> for Body

Source§

fn from(value: Body) -> Self

Converts to this type from the input type.
Source§

impl From<Body> for Body

Source§

fn from(value: Body) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Body
where T: Into<Structure>,

Source§

fn from(value: T) -> Body

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for Body
where T: Into<Structure>,

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for Body
where T: Into<Structure>,

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
Source§

impl<'de> IntoDeserializer<'de, Error> for Body

Source§

type Deserializer = NewtypeStructDeserializer<Vec<Structure>>

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl<'a> IntoIterator for &'a Body

Source§

type Item = &'a Structure

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut Body

Source§

type Item = &'a mut Structure

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Body

Source§

type Item = Structure

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Body

Source§

fn eq(&self, other: &Body) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Body

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Body

Source§

impl StructuralPartialEq for Body

Auto Trait Implementations§

§

impl Freeze for Body

§

impl RefUnwindSafe for Body

§

impl Send for Body

§

impl Sync for Body

§

impl Unpin for Body

§

impl UnwindSafe for Body

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,