Struct toml_edit::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§

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

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

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) -> Selfwhere I: IntoIterator<Item = V>,

Creates a value from an iterator. Read more
source§

impl<'s> IntoIterator for &'s Array

§

type Item = &'s Value

The type of the elements being iterated over.
§

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

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

§

type Item = Value

The type of the elements being iterated over.
§

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

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 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.