pub struct Array { /* private fields */ }
Expand description
Type representing a TOML array,
payload of the Value::Array
variant’s value
Implementations§
Source§impl Array
Formatting
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 if 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);
Sourcepub fn remove(&mut self, index: usize) -> Value
pub fn remove(&mut self, index: usize) -> Value
Removes the value at the given index.
§Examples
let mut arr = toml_edit::Array::new();
arr.push(1);
arr.push("foo");
arr.remove(0);
assert_eq!(arr.len(), 1);
Sourcepub fn retain<F>(&mut self, keep: F)
pub fn retain<F>(&mut self, keep: F)
Retains only the values specified by the keep
predicate.
In other words, remove all values for which keep(&value)
returns false
.
This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.
Sourcepub fn sort_by<F>(&mut self, compare: F)
pub fn sort_by<F>(&mut self, compare: F)
Sorts the slice with a comparator function.
This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case.
The comparator function must define a total ordering for the elements in the slice. If
the ordering is not total, the order of the elements is unspecified. An order is a
total order if it is (for all a
, b
and c
):
- total and antisymmetric: exactly one of
a < b
,a == b
ora > b
is true, and - transitive,
a < b
andb < c
impliesa < c
. The same must hold for both==
and>
.
For example, while f64
doesn’t implement Ord
because NaN != NaN
, we can use
partial_cmp
as our sort function when we know the slice doesn’t contain a NaN
.
Sourcepub fn sort_by_key<K, F>(&mut self, f: F)
pub fn sort_by_key<K, F>(&mut self, f: F)
Sorts the array with a key extraction function.
This sort is stable (i.e., does not reorder equal elements) and O(m * n * log(n)) worst-case, where the key function is O(m).
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
)