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 aMaybeItemthat never panics on out-of-bounds access. get/get_mut: returnOption<&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>
impl<'de> Array<'de>
Sourcepub fn new() -> Self
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.
Sourcepub fn try_with_capacity(cap: usize, arena: &'de Arena) -> Option<Self>
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.
Sourcepub fn span(&self) -> Span
pub fn span(&self) -> Span
Returns the source span, or 0..0 if this array was constructed
programmatically (format-hints mode).
Sourcepub fn push(&mut self, value: Item<'de>, arena: &'de Arena)
pub fn push(&mut self, value: Item<'de>, arena: &'de Arena)
Appends a value to the end of the array.
Sourcepub fn get(&self, index: usize) -> Option<&Item<'de>>
pub fn get(&self, index: usize) -> Option<&Item<'de>>
Returns a reference to the element at the given index.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut Item<'de>>
pub fn get_mut(&mut self, index: usize) -> Option<&mut Item<'de>>
Returns a mutable reference to the element at the given index.
Sourcepub fn remove(&mut self, index: usize) -> Item<'de>
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.
Sourcepub fn pop(&mut self) -> Option<Item<'de>>
pub fn pop(&mut self) -> Option<Item<'de>>
Removes and returns the last element, or None if empty.
Sourcepub fn last_mut(&mut self) -> Option<&mut Item<'de>>
pub fn last_mut(&mut self) -> Option<&mut Item<'de>>
Returns a mutable reference to the last element.
Sourcepub fn as_mut_slice(&mut self) -> &mut [Item<'de>]
pub fn as_mut_slice(&mut self) -> &mut [Item<'de>]
Returns the contents as a mutable slice.
Sourcepub fn as_item(&self) -> &Item<'de>
pub fn as_item(&self) -> &Item<'de>
Converts this Array into an Item with the same span and payload.
Sourcepub fn into_item(self) -> Item<'de>
pub fn into_item(self) -> Item<'de>
Converts this Array into an Item with the same span and payload.
Sourcepub fn style(&self) -> ArrayStyle
pub fn style(&self) -> ArrayStyle
Returns the ArrayStyle recorded on this array.
Sourcepub fn set_style(&mut self, kind: ArrayStyle)
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§impl<'de> Array<'de>
impl<'de> Array<'de>
Sourcepub fn is_auto_style(&self) -> bool
Available on crate feature to-toml only.
pub fn is_auto_style(&self) -> bool
to-toml only.Returns true if this array has automatic style resolution pending.
Sourcepub fn is_expanded(&self) -> bool
Available on crate feature to-toml only.
pub fn is_expanded(&self) -> bool
to-toml only.Returns true if this inline array should be emitted in multiline
format with one element per line.
Sourcepub fn set_expanded(&mut self)
Available on crate feature to-toml only.
pub fn set_expanded(&mut self)
to-toml only.Marks this inline array for multiline emission.
Sourcepub fn clear_expanded(&mut self)
Available on crate feature to-toml only.
pub fn clear_expanded(&mut self)
to-toml only.Clears the multiline emission hint.
Trait Implementations§
Source§impl<'a, 'de> IntoIterator for &'a Array<'de>
impl<'a, 'de> IntoIterator for &'a Array<'de>
Source§impl<'a, 'de> IntoIterator for &'a mut Array<'de>
impl<'a, 'de> IntoIterator for &'a mut Array<'de>
Source§impl<'de> IntoIterator for Array<'de>
impl<'de> IntoIterator for Array<'de>
Source§impl ToToml for Array<'_>
Available on crate feature to-toml only.
impl ToToml for Array<'_>
to-toml only.