Enum toml_edit::Item

source ·
pub enum Item {
    None,
    Value(Value),
    Table(Table),
    ArrayOfTables(ArrayOfTables),
}
Expand description

Type representing either a value, a table, an array of tables, or none.

Variants§

§

None

Type representing none.

§

Value(Value)

Type representing value.

§

Table(Table)

Type representing table.

§

ArrayOfTables(ArrayOfTables)

Type representing array of tables.

Implementations§

source§

impl Item

source

pub fn or_insert(&mut self, item: Item) -> &mut Item

Sets self to the given item iff self is none and returns a mutable reference to self.

source§

impl Item

Downcasting

source

pub fn type_name(&self) -> &'static str

Text description of value type

source

pub fn get<I: Index>(&self, index: I) -> Option<&Item>

Index into a TOML array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array.

Returns None if:

  • The type of self does not match the type of the index, for example if the index is a string and self is an array or a number.
  • The given key does not exist in the map or the given index is not within the bounds of the array.
source

pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Item>

Mutably index into a TOML array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array.

Returns None if:

  • The type of self does not match the type of the index, for example if the index is a string and self is an array or a number.
  • The given key does not exist in the map or the given index is not within the bounds of the array.
source

pub fn as_value(&self) -> Option<&Value>

Casts self to value.

source

pub fn as_table(&self) -> Option<&Table>

Casts self to table.

source

pub fn as_array_of_tables(&self) -> Option<&ArrayOfTables>

Casts self to array of tables.

source

pub fn as_value_mut(&mut self) -> Option<&mut Value>

Casts self to mutable value.

source

pub fn as_table_mut(&mut self) -> Option<&mut Table>

Casts self to mutable table.

source

pub fn as_array_of_tables_mut(&mut self) -> Option<&mut ArrayOfTables>

Casts self to mutable array of tables.

source

pub fn into_value(self) -> Result<Value, Self>

Casts self to value.

source

pub fn make_value(&mut self)

In-place convert to a value

source

pub fn into_table(self) -> Result<Table, Self>

Casts self to table.

source

pub fn into_array_of_tables(self) -> Result<ArrayOfTables, Self>

Casts self to array of tables.

source

pub fn is_value(&self) -> bool

Returns true iff self is a value.

source

pub fn is_table(&self) -> bool

Returns true iff self is a table.

source

pub fn is_array_of_tables(&self) -> bool

Returns true iff self is an array of tables.

source

pub fn is_none(&self) -> bool

Returns true iff self is None.

source

pub fn as_integer(&self) -> Option<i64>

Casts self to integer.

source

pub fn is_integer(&self) -> bool

Returns true iff self is an integer.

source

pub fn as_float(&self) -> Option<f64>

Casts self to float.

source

pub fn is_float(&self) -> bool

Returns true iff self is a float.

source

pub fn as_bool(&self) -> Option<bool>

Casts self to boolean.

source

pub fn is_bool(&self) -> bool

Returns true iff self is a boolean.

source

pub fn as_str(&self) -> Option<&str>

Casts self to str.

source

pub fn is_str(&self) -> bool

Returns true iff self is a string.

source

pub fn as_datetime(&self) -> Option<&Datetime>

Casts self to date-time.

source

pub fn is_datetime(&self) -> bool

Returns true iff self is a date-time.

source

pub fn as_array(&self) -> Option<&Array>

Casts self to array.

source

pub fn as_array_mut(&mut self) -> Option<&mut Array>

Casts self to mutable array.

source

pub fn is_array(&self) -> bool

Returns true iff self is an array.

source

pub fn as_inline_table(&self) -> Option<&InlineTable>

Casts self to inline table.

source

pub fn as_inline_table_mut(&mut self) -> Option<&mut InlineTable>

Casts self to mutable inline table.

source

pub fn is_inline_table(&self) -> bool

Returns true iff self is an inline table.

source

pub fn as_table_like(&self) -> Option<&dyn TableLike>

Casts self to either a table or an inline table.

source

pub fn as_table_like_mut(&mut self) -> Option<&mut dyn TableLike>

Casts self to either a table or an inline table.

source

pub fn is_table_like(&self) -> bool

Returns true iff self is either a table, or an inline table.

Trait Implementations§

source§

impl Clone for Item

source§

fn clone(&self) -> Item

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 Item

source§

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

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

impl Default for Item

source§

fn default() -> Self

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

impl Display for Item

source§

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

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

impl FromStr for Item

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a value from a &str

§

type Err = TomlError

The associated error which can be returned from parsing.
source§

impl<I> Index<I> for Itemwhere
    I: Index,

§

type Output = Item

The returned type after indexing.
source§

fn index(&self, index: I) -> &Item

Performs the indexing (container[index]) operation. Read more
source§

impl<I> IndexMut<I> for Itemwhere
    I: Index,

source§

fn index_mut(&mut self, index: I) -> &mut Item

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Item

§

impl Send for Item

§

impl Sync for Item

§

impl Unpin for Item

§

impl UnwindSafe for Item

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.