Enum achan::Value

source ·
pub enum Value {
    Null,
    Boolean(bool),
    Number(f64),
    String(String),
    List(Vec<Value>),
    Map(BTreeMap<String, Value>),
}
Expand description

Represents any value.

Variants§

§

Null

Represents the absence of a value.

§

Boolean(bool)

Represents true or false.

§

Number(f64)

Represents any number.

§

String(String)

Represents any string of characters.

§

List(Vec<Value>)

Represents any sequence of values.

§

Map(BTreeMap<String, Value>)

Represents any mapping from strings to values.

Implementations§

source§

impl Value

source

pub fn is_null(&self) -> bool

Returns true if this Value represents a null value.

source

pub fn is_boolean(&self) -> bool

Returns true if this Value represents a boolean.

source

pub fn is_number(&self) -> bool

Returns true if this Value represents a number.

source

pub fn is_string(&self) -> bool

Returns true if this Value represents a string.

source

pub fn is_list(&self) -> bool

Returns true if this Value represents a list.

source

pub fn is_map(&self) -> bool

Returns true if this Value represents a map.

source§

impl Value

source

pub fn as_null(&self) -> Option<()>

Returns Some if this Value represents a null value, otherwise returns None.

source

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

Returns the underlying boolean, if that’s what this Value represents.

source

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

Returns the underlying number, if that’s what this Value represents.

source

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

Returns a reference to the underlying string, if that’s what this Value represents.

source

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

Returns a reference to the underlying list, if that’s what this Value represents.

source

pub fn as_map(&self) -> Option<&BTreeMap<String, Self>>

Returns a reference to the underlying map, if that’s what this Value represents.

source§

impl Value

source

pub fn into_string(self) -> Result<String, Self>

If the Value represented a string it is returned in the Ok result, else the Value is preserved in the Err result.

source

pub fn into_list(self) -> Result<Vec<Self>, Self>

If the Value represented a list it is returned in the Ok result, else the Value is preserved in the Err result.

source

pub fn into_map(self) -> Result<BTreeMap<String, Self>, Self>

If the Value represented a map it is returned in the Ok result, else the Value is preserved in the Err result.

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 Default for Value

source§

fn default() -> Value

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

impl Display for Value

source§

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

Display a Value as a string.

For simplicity, the JSON string representation is chosen.

source§

impl<K: Clone + Into<String>, V: Clone + Into<Value>> From<&[(K, V)]> for Value

source§

fn from(value: &[(K, V)]) -> Self

Converts to this type from the input type.
source§

impl<V: Clone + Into<Value>> From<&[V]> for Value

source§

fn from(value: &[V]) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Value

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl From<()> for Value

source§

fn from(_: ()) -> Self

Converts to this type from the input type.
source§

impl<V: Into<Value>> From<BTreeMap<String, V>> for Value

source§

fn from(value: BTreeMap<String, V>) -> Self

Converts to this type from the input type.
source§

impl<V: Into<Value>> From<Option<V>> for Value

source§

fn from(value: Option<V>) -> 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<V: Into<Value>> From<Vec<V>> for Value

source§

fn from(value: Vec<V>) -> 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

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(value: f64) -> 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<i8> for Value

source§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

impl From<isize> for Value

source§

fn from(value: isize) -> 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 From<u64> for Value

source§

fn from(value: u64) -> 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<usize> for Value

source§

fn from(value: usize) -> Self

Converts to this type from the input type.
source§

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

source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

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

source§

fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self

Creates a value from an iterator. 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 PartialOrd for Value

source§

fn partial_cmp(&self, other: &Value) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

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