Struct hcl_edit::structure::Body

source ·
pub struct Body { /* private fields */ }
Expand description

Represents an HCL config file body.

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

Implementations§

source§

impl Body

source

pub fn new() -> Self

Constructs a new, empty Body.

source

pub fn with_capacity(capacity: usize) -> Self

Constructs a new, empty Body with at least the specified capacity.

source

pub fn is_empty(&self) -> bool

Returns true if the body contains no structures.

source

pub fn len(&self) -> usize

Returns the number of structures in the body, also referred to as its ‘length’.

source

pub fn clear(&mut self)

Clears the body, removing all structures.

source

pub fn get(&self, index: usize) -> Option<&Structure>

Returns a reference to the structure at the given index, or None if the index is out of bounds.

source

pub fn get_mut(&mut self, index: usize) -> Option<&mut Structure>

Returns a mutable reference to the structure at the given index, or None if the index is out of bounds.

source

pub fn insert(&mut self, index: usize, structure: impl Into<Structure>)

Inserts a structure at position index within the body, shifting all structures after it to the right.

Panics

Panics if index > len.

source

pub fn push(&mut self, structure: impl Into<Structure>)

Appends a structure to the back of the body.

Panics

Panics if the new capacity exceeds isize::MAX bytes.

source

pub fn pop(&mut self) -> Option<Structure>

Removes the last structure from the body and returns it, or None if it is empty.

source

pub fn remove(&mut self, index: usize) -> Structure

Removes and returns the structure at position index within the body, shifting all elements after it to the left.

Like Vec::remove, the structure is removed by shifting all of the structures that follow it, preserving their relative order. This perturbs the index of all of those elements!

Panics

Panics if index is out of bounds.

source

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

An iterator visiting all body structures in insertion order. The iterator element type is &'a Structure.

source

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

An iterator visiting all body structures in insertion order, with mutable references to the values. The iterator element type is &'a mut Structure.

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 Decorate for Body

source§

fn decor(&self) -> &Decor

Returns a reference to the object’s Decor.
source§

fn decor_mut(&mut self) -> &mut Decor

Returns a mutable reference to the object’s Decor.
source§

fn decorate(&mut self, decor: impl Into<Decor>)

Decorate the object with decor in-place.
source§

fn decorated(self, decor: impl Into<Decor>) -> Selfwhere Self: Sized,

Decorate the object with decor and return the modified value.
source§

impl Default for Body

source§

fn default() -> Body

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

impl Display for Body

source§

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

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

impl<T> Extend<T> for Bodywhere 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 From<Body> for BlockBody

source§

fn from(value: Body) -> Self

Converts to this type from the input type.
source§

impl From<Vec<Structure, Global>> for Body

source§

fn from(structures: Vec<Structure>) -> Self

Converts to this type from the input type.
source§

impl<T> FromIterator<T> for Bodywhere T: Into<Structure>,

source§

fn from_iter<I>(iterable: I) -> Selfwhere I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
source§

impl FromStr for Body

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl<'a> IntoIterator for &'a Body

§

type Item = &'a Structure

The type of the elements being iterated over.
§

type IntoIter = Box<dyn Iterator<Item = &'a Structure> + 'a, Global>

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

§

type Item = &'a mut Structure

The type of the elements being iterated over.
§

type IntoIter = Box<dyn Iterator<Item = &'a mut Structure> + 'a, Global>

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

§

type Item = Structure

The type of the elements being iterated over.
§

type IntoIter = Box<dyn Iterator<Item = Structure> + 'static, Global>

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<Body> for Body

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Span for Body

source§

fn span(&self) -> Option<Range<usize>>

Obtains the span information. This only returns Some if the value was emitted by the parser. Read more
source§

impl Eq for Body

source§

impl StructuralEq for Body

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.