pub struct Array { /* private fields */ }
Expand description
Type representing a TOML array,
payload of the Value::Array
variant’s value
Implementations§
source§impl Array
impl Array
Formatting
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
sourcepub fn trailing_comma(&self) -> bool
pub fn trailing_comma(&self) -> bool
Whether the array will use a trailing comma
sourcepub fn set_trailing(&mut self, trailing: impl Into<RawString>)
pub fn set_trailing(&mut self, trailing: impl Into<RawString>)
Set whitespace after last element
source§impl Array
impl Array
sourcepub fn iter_mut(&mut self) -> ArrayIterMut<'_>
pub fn iter_mut(&mut self) -> ArrayIterMut<'_>
Returns an iterator over all values.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the underlying Vec.
In some rare cases, placeholder elements will exist. For a more accurate count, call
a.iter().count()
Examples
let mut arr = toml_edit::Array::new();
arr.push(1);
arr.push("foo");
assert_eq!(arr.len(), 2);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true iff self.len() == 0
.
Examples
let mut arr = toml_edit::Array::new();
assert!(arr.is_empty());
arr.push(1);
arr.push("foo");
assert!(! arr.is_empty());
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the array, removing all values. Keeps the allocated memory for reuse.
sourcepub fn get(&self, index: usize) -> Option<&Value>
pub fn get(&self, index: usize) -> Option<&Value>
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 Value>
pub fn get_mut(&mut self, index: usize) -> Option<&mut Value>
Returns a reference to the value at the given index, or None
if the index is out of
bounds.
sourcepub fn push<V: Into<Value>>(&mut self, v: V)
pub fn push<V: Into<Value>>(&mut self, v: V)
Appends a new value to the end of the array, applying default formatting to it.
Examples
let mut arr = toml_edit::Array::new();
arr.push(1);
arr.push("foo");
sourcepub fn push_formatted(&mut self, v: Value)
pub fn push_formatted(&mut self, v: Value)
Appends a new, already formatted value to the end of the array.
Examples
let formatted_value = "'literal'".parse::<toml_edit::Value>().unwrap();
let mut arr = toml_edit::Array::new();
arr.push_formatted(formatted_value);
sourcepub fn insert_formatted(&mut self, index: usize, v: Value)
pub fn insert_formatted(&mut self, index: usize, v: Value)
Inserts an already formatted value at the given position within the array, shifting all values after it to the right.
Panics
Panics if index > len
.
Examples
let mut arr = toml_edit::Array::new();
arr.push(1);
arr.push("foo");
let formatted_value = "'start'".parse::<toml_edit::Value>().unwrap();
arr.insert_formatted(0, formatted_value);
sourcepub fn replace_formatted(&mut self, index: usize, v: Value) -> Value
pub fn replace_formatted(&mut self, index: usize, v: Value) -> Value
Replaces the element at the given position within the array with an already formatted value.
Panics
Panics if index >= len
.
Examples
let mut arr = toml_edit::Array::new();
arr.push(1);
arr.push("foo");
let formatted_value = "'start'".parse::<toml_edit::Value>().unwrap();
arr.replace_formatted(0, formatted_value);
Trait Implementations§
source§impl<V: Into<Value>> Extend<V> for Array
impl<V: Into<Value>> Extend<V> for Array
source§fn extend<T: IntoIterator<Item = V>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = V>>(&mut self, iter: 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
)