hcl_edit::expr

Struct Array

Source
pub struct Array { /* private fields */ }
Expand description

Type representing a HCL array.

Implementations§

Source§

impl Array

Source

pub fn new() -> Self

Constructs a new, empty Array.

Source

pub fn with_capacity(capacity: usize) -> Self

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

Source

pub fn is_empty(&self) -> bool

Returns true if the array contains no elements.

Source

pub fn len(&self) -> usize

Returns the number of elements in the array, also referred to as its ‘length’.

Source

pub fn clear(&mut self)

Clears the array, removing all values.

Source

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

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

Source

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

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

Source

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

Inserts an element at position index within the array, shifting all elements after it to the right.

§Panics

Panics if index > len.

Source

pub fn push(&mut self, value: impl Into<Expression>)

Appends an element to the back of the array.

§Panics

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

Source

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

Removes the last element from the array and returns it, or None if it is empty.

Source

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

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

Like Vec::remove, the element is removed by shifting all of the elements 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 values in insertion order. The iterator element type is &'a Expression.

Source

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

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

Source

pub fn trailing(&self) -> &RawString

Return a reference to raw trailing decor before the array’s closing ].

Source

pub fn set_trailing(&mut self, trailing: impl Into<RawString>)

Set the raw trailing decor before the array’s closing ].

Source

pub fn trailing_comma(&self) -> bool

Returns true if the array uses a trailing comma.

Source

pub fn set_trailing_comma(&mut self, yes: bool)

Set whether the array will use a trailing comma.

Trait Implementations§

Source§

impl Clone for Array

Source§

fn clone(&self) -> Array

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 Array

Source§

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

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

impl Decorate for Array

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>) -> Self
where Self: Sized,

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

impl Default for Array

Source§

fn default() -> Array

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

impl<T> Extend<T> for Array
where T: Into<Expression>,

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<Array> for Expression

Source§

fn from(value: Array) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Expression>> for Array

Source§

fn from(values: Vec<Expression>) -> Self

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for Array
where T: Into<Expression>,

Source§

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

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a Array

Source§

type Item = &'a Expression

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = &'a Expression> + '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 Array

Source§

type Item = &'a mut Expression

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = &'a mut Expression> + '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 Array

Source§

type Item = Expression

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = Expression>>

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 Array

Source§

fn eq(&self, other: &Self) -> 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 Span for Array

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 Array

Auto Trait Implementations§

§

impl Freeze for Array

§

impl RefUnwindSafe for Array

§

impl Send for Array

§

impl Sync for Array

§

impl Unpin for Array

§

impl UnwindSafe for Array

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