[go: up one dir, main page]

Enum toml::Value

source ·
pub enum Value {
    String(String),
    Integer(i64),
    Float(f64),
    Boolean(bool),
    Datetime(String),
    Array(Array),
    Table(Table),
}
Expand description

Representation of a TOML value.

Variants§

§

String(String)

§

Integer(i64)

§

Float(f64)

§

Boolean(bool)

§

Datetime(String)

§

Array(Array)

§

Table(Table)

Implementations§

source§

impl Value

source

pub fn same_type(&self, other: &Value) -> bool

Tests whether this and another value have the same type.

source

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

Returns a human-readable representation of the type of this value.

source

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

Extracts the string of this value if it is a string.

source

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

Extracts the integer value if it is an integer.

source

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

Extracts the float value if it is a float.

source

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

Extracts the boolean value if it is a boolean.

source

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

Extracts the datetime value if it is a datetime.

Note that a parsed TOML value will only contain ISO 8601 dates. An example date is:

1979-05-27T07:32:00Z
source

pub fn as_slice(&self) -> Option<&[Value]>

Extracts the array value if it is an array.

source

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

Extracts the table value if it is a table.

source

pub fn lookup<'a>(&'a self, path: &'a str) -> Option<&'a Value>

Lookups for value at specified path.

Uses ‘.’ as a path separator.

Note: arrays have zero-based indexes.

Note: empty path returns self.

let toml = r#"
     [test]
     foo = "bar"

     [[values]]
     foo = "baz"

     [[values]]
     foo = "qux"
"#;
let value: toml::Value = toml.parse().unwrap();

let foo = value.lookup("test.foo").unwrap();
assert_eq!(foo.as_str().unwrap(), "bar");

let foo = value.lookup("values.1.foo").unwrap();
assert_eq!(foo.as_str().unwrap(), "qux");

let no_bar = value.lookup("test.bar");
assert_eq!(no_bar.is_none(), true);

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

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 Value

source§

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

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

impl Display for Value

source§

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

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

impl Encodable for Value

source§

fn encode<E>(&self, e: &mut E) -> Result<(), E::Error>
where E: Encoder,

Serialize a value using an Encoder.
source§

impl FromStr for Value

§

type Err = Vec<ParserError>

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

fn from_str(s: &str) -> Result<Value, Vec<ParserError>>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for Value

source§

fn eq(&self, other: &Value) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

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§

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

🔬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,

§

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>,

§

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>,

§

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.