Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    Int(i64),
    Float(f64),
    String(String),
    Date(Date),
    Instant(Instant),
    Duration(Duration),
    Array(Vec<Self>),
    Object(Object),
}
Expand description

Any SOML value.

let value: soml::Value = "port: 8080\nhosts: ['a', 'b']".parse()?;

assert_eq!(value.get("port").and_then(soml::Value::as_i64), Some(8080));
assert_eq!(value.get("hosts").and_then(|hosts| hosts.get(1)).and_then(soml::Value::as_str), Some("b"));

An int and a float are different types, as in the spec: Value::Int(3) and Value::Float(3.0) are not equal, and as_f64() does not convert an int.

Variants§

§

Null

null.

§

Bool(bool)

true or false.

§

Int(i64)

An int.

§

Float(f64)

A float. A float that came from a document is never NaN, and it is never negative zero.

§

String(String)

A string.

§

Date(Date)

A Gregorian calendar date.

§

Instant(Instant)

An instant.

§

Duration(Duration)

A duration.

§

Array(Vec<Self>)

An array.

§

Object(Object)

An object.

Implementations§

Source§

impl Value

Source

pub fn get(&self, index: impl Index) -> Option<&Self>

The member of an object with this key, or the item of an array at this position. None for a missing member or item, and for a value of another type.

Source

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

A mutable reference to the member of an object with this key, or the item of an array at this position.

Source

pub const fn is_null(&self) -> bool

Whether the value is null.

Source

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

The bool, if the value is one.

Source

pub const fn as_i64(&self) -> Option<i64>

The int, if the value is one.

Source

pub const fn as_f64(&self) -> Option<f64>

The float, if the value is one. An int is not converted, because an int and a float are different types.

Source

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

The string, if the value is one.

Source

pub const fn as_date(&self) -> Option<Date>

The date, if the value is one.

Source

pub const fn as_instant(&self) -> Option<Instant>

The instant, if the value is one.

Source

pub const fn as_duration(&self) -> Option<Duration>

The duration, if the value is one.

Source

pub const fn as_array(&self) -> Option<&Vec<Self>>

The items, if the value is an array.

Source

pub const fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>

The items, if the value is an array, to change.

Source

pub const fn as_object(&self) -> Option<&Object>

The members, if the value is an object.

Source

pub const fn as_object_mut(&mut self) -> Option<&mut Object>

The members, if the value is an object, to change.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 Default for Value

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&str> for Value

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<BTreeMap<String, Value>> for Value

Source§

fn from(value: Object) -> Self

Converts to this type from the input type.
Source§

impl From<Date> for Value

Source§

fn from(value: Date) -> Self

Converts to this type from the input type.
Source§

impl From<Duration> for Value

Source§

fn from(value: Duration) -> Self

Converts to this type from the input type.
Source§

impl From<Instant> for Value

Source§

fn from(value: Instant) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Self>> From<Option<T>> for Value

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Self>> From<Vec<T>> for Value

Source§

fn from(value: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Self>, const N: usize> From<[T; N]> for Value

Source§

fn from(value: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(value: f32) -> Self

Uses the shortest decimal that reads back as the same f32, so 0.1f32 becomes 0.1, not 0.10000000149011612.

Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<String>, V: Into<Self>> FromIterator<(K, V)> for Value

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iterator: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: Into<Self>> FromIterator<T> for Value

Source§

fn from_iter<I: IntoIterator<Item = T>>(iterator: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for Value

Reads a document, which is always an object or an array.

Source§

type Err = Error

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

fn from_str(text: &str) -> Result<Self, Error>

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

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Value

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
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 UnsafeUnpin 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§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.