Skip to main content

Array

Struct Array 

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

A TOML array with span information.

An Array stores Item elements in insertion order with arena-allocated backing storage. It carries the byte-offset Span from the source document.

§Accessing elements

  • Index operator: array[i] returns a MaybeItem that never panics on out-of-bounds access.
  • get / get_mut: return Option<&Item> / Option<&mut Item>.
  • Iteration: for item in &array { ... }.

§Mutation

push appends an element. An Arena is required because array storage is arena-allocated.

Implementations§

Source§

impl<'de> Array<'de>

Source

pub fn new() -> Self

Creates an empty array in format-hints mode (no source span).

The array starts with automatic style: normalization will choose between inline and header (array-of-tables) based on content. Call set_style to override.

Source

pub fn try_with_capacity(cap: usize, arena: &'de Arena) -> Option<Self>

Creates an empty array with pre-allocated capacity.

Returns None if cap exceeds u32::MAX.

Source

pub fn span(&self) -> Span

Returns the source span, or 0..0 if this array was constructed programmatically (format-hints mode).

Source

pub fn push(&mut self, value: Item<'de>, arena: &'de 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 remove(&mut self, index: usize) -> Item<'de>

Removes and returns the element at index, shifting subsequent elements to the left.

§Panics

Panics if index is out of bounds.

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.

Source

pub fn as_item(&self) -> &Item<'de>

Converts this Array into an Item with the same span and payload.

Source

pub fn into_item(self) -> Item<'de>

Converts this Array into an Item with the same span and payload.

Source

pub fn style(&self) -> ArrayStyle

Returns the ArrayStyle recorded on this array.

Source

pub fn set_style(&mut self, kind: ArrayStyle)

Pins the ArrayStyle used when this array is emitted.

Arrays built programmatically start out with an unresolved style and emit picks a rendering from their contents. Calling this method locks in kind so the choice survives emission unchanged.

Source

pub fn clone_in(&self, arena: &'de Arena) -> Array<'de>

Deep-clones this array into arena. Keys and strings are shared with the source.

Source§

impl<'de> Array<'de>

Source

pub fn is_auto_style(&self) -> bool

Available on crate feature to-toml only.

Returns true if this array has automatic style resolution pending.

Source

pub fn is_expanded(&self) -> bool

Available on crate feature to-toml only.

Returns true if this inline array should be emitted in multiline format with one element per line.

Source

pub fn set_expanded(&mut self)

Available on crate feature to-toml only.

Marks this inline array for multiline emission.

Source

pub fn clear_expanded(&mut self)

Available on crate feature to-toml only.

Clears the multiline emission hint.

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
Source§

impl ToToml for Array<'_>

Available on crate feature to-toml only.
Source§

fn to_toml<'a>(&'a self, arena: &'a Arena) -> Result<Item<'a>, ToTomlError>

Produces a TOML Item representing this value. Read more
Source§

fn to_optional_toml<'a>( &'a self, arena: &'a Arena, ) -> Result<Option<Item<'a>>, ToTomlError>

Produces an optional TOML Item representing this value. Read more
Source§

impl Send for Array<'_>

Source§

impl Sync for Array<'_>

Auto Trait Implementations§

§

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

§

impl<'de> RefUnwindSafe 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.