Skip to main content

Array

Struct Array 

Source
pub struct Array<'de> { /* private fields */ }
Expand description

A growable array of TOML Items.

Arrays support indexing with usize via the [] operator, which returns a MaybeItem — out-of-bounds access returns a None variant instead of panicking. Use get / get_mut for Option-based access, or iterate with a for loop.

Mutation methods (push, with_capacity) require an Arena because array storage is arena-allocated.

Implementations§

Source§

impl<'de> Array<'de>

Source

pub fn new() -> Self

Creates an empty array.

Source

pub fn with_capacity(cap: u32, arena: &Arena) -> Self

Creates an array with pre-allocated capacity.

Source

pub fn with_single(value: Item<'de>, arena: &Arena) -> Self

Creates an array containing a single value.

Source

pub fn push(&mut self, value: Item<'de>, arena: &Arena)

Appends a value to the end of the array.

Source

pub fn len(&self) -> usize

Returns the number of elements.

Source

pub fn is_empty(&self) -> bool

Returns true if the array contains no elements.

Source

pub fn get(&self, index: usize) -> Option<&Item<'de>>

Returns a reference to the element at the given index.

Source

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

Returns a mutable reference to the element at the given index.

Source

pub fn pop(&mut self) -> Option<Item<'de>>

Removes and returns the last element, or None if empty.

Source

pub fn last_mut(&mut self) -> Option<&mut Item<'de>>

Returns a mutable reference to the last element.

Source

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

Returns an iterator over references to the elements.

Source

pub fn as_slice(&self) -> &[Item<'de>]

Returns the contents as a slice.

Source

pub fn as_mut_slice(&mut self) -> &mut [Item<'de>]

Returns the contents as a mutable slice.

Trait Implementations§

Source§

impl Debug for Array<'_>

Source§

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

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

impl<'de> Default for Array<'de>

Source§

fn default() -> Self

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

impl<'de> Index<usize> for Array<'de>

Source§

type Output = MaybeItem<'de>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, 'de> IntoIterator for &'a Array<'de>

Source§

type Item = &'a Item<'de>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Item<'de>>

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, 'de> IntoIterator for &'a mut Array<'de>

Source§

type Item = &'a mut Item<'de>

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, Item<'de>>

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<'de> IntoIterator for Array<'de>

Source§

type Item = Item<'de>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<'de>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'de> Freeze for Array<'de>

§

impl<'de> RefUnwindSafe for Array<'de>

§

impl<'de> !Send for Array<'de>

§

impl<'de> !Sync for Array<'de>

§

impl<'de> Unpin for Array<'de>

§

impl<'de> UnsafeUnpin for Array<'de>

§

impl<'de> UnwindSafe for Array<'de>

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