toml_edit

Struct Array

Source
pub struct Array { /* private fields */ }
Expand description

Type representing a TOML array, payload of the Value::Array variant’s value

Implementations§

Source§

impl Array

Constructors

See also FromIterator

Source

pub fn new() -> Self

Create an empty Array

§Examples
let mut arr = toml_edit::Array::new();
Source§

impl Array

Formatting

Source

pub fn fmt(&mut self)

Auto formats the array.

Source

pub fn set_trailing_comma(&mut self, yes: bool)

Set whether the array will use a trailing comma

Source

pub fn trailing_comma(&self) -> bool

Whether the array will use a trailing comma

Source

pub fn set_trailing(&mut self, trailing: impl Into<RawString>)

Set whitespace after last element

Source

pub fn trailing(&self) -> &RawString

Whitespace after last element

Source

pub fn decor_mut(&mut self) -> &mut Decor

Returns the surrounding whitespace

Source

pub fn decor(&self) -> &Decor

Returns the surrounding whitespace

Source

pub fn span(&self) -> Option<Range<usize>>

The location within the original document

This generally requires an ImDocument.

Source§

impl Array

Source

pub fn iter(&self) -> ArrayIter<'_>

Returns an iterator over all values.

Source

pub fn iter_mut(&mut self) -> ArrayIterMut<'_>

Returns an iterator over all values.

Source

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);
Source

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());
Source

pub fn clear(&mut self)

Clears the array, removing all values. Keeps the allocated memory for reuse.

Source

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.

Source

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.

Source

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");
Source

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);
Source

pub fn insert<V: Into<Value>>(&mut self, index: usize, v: V)

Inserts an element at the given position within the array, applying default formatting to it and 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");

arr.insert(0, "start");
Source

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);
Source

pub fn replace<V: Into<Value>>(&mut self, index: usize, v: V) -> Value

Replaces the element at the given position within the array, preserving existing formatting.

§Panics

Panics if index >= len.

§Examples
let mut arr = toml_edit::Array::new();
arr.push(1);
arr.push("foo");

arr.replace(0, "start");
Source

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);
Source

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);
Source

pub fn retain<F>(&mut self, keep: F)
where F: FnMut(&Value) -> bool,

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.

Source

pub fn sort_by<F>(&mut self, compare: F)
where F: FnMut(&Value, &Value) -> Ordering,

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 or a > b is true, and
  • transitive, a < b and b < c implies a < 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.

Source

pub fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(&Value) -> K, K: Ord,

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 Clone for Array

Source§

fn clone(&self) -> Array

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Array

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Array

Source§

fn default() -> Array

Returns the “default value” for a type. Read more
Source§

impl Display for Array

Available on crate feature display only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: Into<Value>> Extend<V> for Array

Source§

fn extend<T: IntoIterator<Item = V>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<Array> for Value

Source§

fn from(array: Array) -> Self

Converts to this type from the input type.
Source§

impl<V: Into<Value>> FromIterator<V> for Array

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = V>,

Creates a value from an iterator. Read more
Source§

impl<'s> IntoIterator for &'s Array

Source§

type Item = &'s Value

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = &'s Value> + 's>

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 IntoIterator for Array

Source§

type Item = Value

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = Value>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 128 bytes