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);
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.
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
)source§impl<V: Into<Value>> FromIterator<V> for Array
impl<V: Into<Value>> FromIterator<V> for Array
source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = V>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = V>,
source§impl<'s> IntoIterator for &'s Array
impl<'s> IntoIterator for &'s Array
Auto Trait Implementations§
impl Freeze for Array
impl RefUnwindSafe for Array
impl Send for Array
impl Sync for Array
impl Unpin for Array
impl UnwindSafe for Array
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)