pub struct Array { /* private fields */ }
Expand description
Type representing a HCL array.
Implementations§
Source§impl Array
impl Array
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty Array
with at least the specified capacity.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the array, also referred to as its ‘length’.
Sourcepub fn get(&self, index: usize) -> Option<&Expression>
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.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut Expression>
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.
Sourcepub fn insert(&mut self, index: usize, value: impl Into<Expression>)
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
.
Sourcepub fn push(&mut self, value: impl Into<Expression>)
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.
Sourcepub fn pop(&mut self) -> Option<Expression>
pub fn pop(&mut self) -> Option<Expression>
Removes the last element from the array and returns it, or None
if it is empty.
Sourcepub fn remove(&mut self, index: usize) -> Expression
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.
Sourcepub fn iter(&self) -> Iter<'_>
pub fn iter(&self) -> Iter<'_>
An iterator visiting all values in insertion order. The iterator element type is &'a Expression
.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_>
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
.
Sourcepub fn trailing(&self) -> &RawString
pub fn trailing(&self) -> &RawString
Return a reference to raw trailing decor before the array’s closing ]
.
Sourcepub fn set_trailing(&mut self, trailing: impl Into<RawString>)
pub fn set_trailing(&mut self, trailing: impl Into<RawString>)
Set the raw trailing decor before the array’s closing ]
.
Sourcepub fn trailing_comma(&self) -> bool
pub fn trailing_comma(&self) -> bool
Returns true
if the array uses a trailing comma.
Sourcepub fn set_trailing_comma(&mut self, yes: bool)
pub fn set_trailing_comma(&mut self, yes: bool)
Set whether the array will use a trailing comma.
Trait Implementations§
Source§impl<T> Extend<T> for Arraywhere
T: Into<Expression>,
impl<T> Extend<T> for Arraywhere
T: Into<Expression>,
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
)