pub struct Body(pub Vec<Structure>);
Expand description
Tuple Fields§
§0: Vec<Structure>
Implementations§
Source§impl Body
impl Body
Sourcepub fn into_inner(self) -> Vec<Structure>
pub fn into_inner(self) -> Vec<Structure>
Consumes self
and returns the wrapped Vec<Structure>
.
Sourcepub fn builder() -> BodyBuilder
pub fn builder() -> BodyBuilder
Creates a new BodyBuilder
to start building a new Body
.
Sourcepub fn iter(&self) -> Iter<'_> ⓘ
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:?}");
}
Sourcepub fn iter_mut(&mut self) -> IterMut<'_> ⓘ
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)),
]);
Sourcepub fn attributes(&self) -> Attributes<'_> ⓘ
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)]);
Sourcepub fn attributes_mut(&mut self) -> AttributesMut<'_> ⓘ
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)),
]);
Sourcepub fn into_attributes(self) -> IntoAttributes ⓘ
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)]);
Sourcepub fn blocks(&self) -> Blocks<'_> ⓘ
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")]);
Sourcepub fn blocks_mut(&mut self) -> BlocksMut<'_> ⓘ
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)),
]);
Sourcepub fn into_blocks(self) -> IntoBlocks ⓘ
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<'de> Deserialize<'de> for Body
impl<'de> Deserialize<'de> for Body
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Evaluate for Body
impl Evaluate for Body
Source§fn evaluate(&self, ctx: &Context<'_>) -> EvalResult<Self::Output>
fn evaluate(&self, ctx: &Context<'_>) -> EvalResult<Self::Output>
Context
. Read moreSource§fn evaluate_in_place(&mut self, ctx: &Context<'_>) -> EvalResult<(), Errors>
fn evaluate_in_place(&mut self, ctx: &Context<'_>) -> EvalResult<(), Errors>
Source§impl<T> Extend<T> for Body
impl<T> Extend<T> for Body
Source§fn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Format for Body
impl Format for Body
Source§fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>where
W: Write,
fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>where
W: Write,
Source§impl<T> FromIterator<T> for Body
impl<T> FromIterator<T> for Body
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Source§impl<'de> IntoDeserializer<'de, Error> for Body
impl<'de> IntoDeserializer<'de, Error> for Body
Source§type Deserializer = NewtypeStructDeserializer<Vec<Structure>>
type Deserializer = NewtypeStructDeserializer<Vec<Structure>>
Source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
Source§impl<'a> IntoIterator for &'a Body
impl<'a> IntoIterator for &'a Body
Source§impl<'a> IntoIterator for &'a mut Body
impl<'a> IntoIterator for &'a mut Body
Source§impl IntoIterator for Body
impl IntoIterator for Body
impl Eq for Body
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.