Enum Value

Source
pub enum Value {
    Null,
    Bool(bool),
    Number(Number),
    String(String),
    Array(Vec<Spanned<Value>>),
    Object(Map<Spanned<String>, Spanned<Value>>),
}
Expand description

A basic un-Spanned value, with Spanned children. Unless you want to match it, you probably want spanned::Value.

Variants§

§

Null

null

§

Bool(bool)

true or false

§

Number(Number)

A number like 123

§

String(String)

A string like "asdf"

§

Array(Vec<Spanned<Value>>)

An array like [1, 2, 3]

§

Object(Map<Spanned<String>, Spanned<Value>>)

An object like {"a": 1, "b": 2}

Implementations§

Source§

impl Value

Source

pub fn is_null(&self) -> bool

True if self is null

Source

pub fn is_bool(&self) -> bool

True if self is true or false

Source

pub fn is_number(&self) -> bool

True if self is a number like 123

Source

pub fn is_string(&self) -> bool

True if self is a string like "asdf"

Source

pub fn is_array(&self) -> bool

True if self is an array like [1, 2, 3]

Source

pub fn is_object(&self) -> bool

True if self is an object like {"a": 1, "b": 2}

Source

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

Some(()) if self is null`

Source

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

Some(inner) if self is true or false

Source

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

Some(&inner) if self is a number like 123

Source

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

Some(&inner) if self is a string like "asdf"

Source

pub fn as_array(&self) -> Option<&Vec<Spanned<Value>>>

Some(&inner) if self is an array like [1, 2, 3]

Source

pub fn as_object(&self) -> Option<&Map<Spanned<String>, Spanned<Value>>>

Some(&inner) if self is an object like {"a": 1, "b": 2}

Source

pub fn as_bool_mut(&mut self) -> Option<&mut bool>

Some(&mut v) if self is true or false

Source

pub fn as_number_mut(&mut self) -> Option<&mut Number>

Some(&mut v) if self is a number like 123

Source

pub fn as_string_mut(&mut self) -> Option<&mut String>

Some(&mut v) if self is a string like "asdf"

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<Spanned<Value>>>

Some(&mut v) if self is an array like [1, 2, 3]

Source

pub fn as_object_mut( &mut self, ) -> Option<&mut Map<Spanned<String>, Spanned<Value>>>

Some(&mut v) if self is an object like {"a": 1, "b": 2}

Source

pub fn into_null(self) -> Result<(), Self>

Ok(inner) if self is null, otherwise Err(self)

Source

pub fn into_bool(self) -> Result<bool, Self>

Ok(inner) if self is true or false, otherwise Err(self)

Source

pub fn into_number(self) -> Result<Number, Self>

Ok(inner) if self is a number like 123, otherwise Err(self)

Source

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

Ok(inner) if self is a string like "asdf", otherwise Err(self)

Source

pub fn into_array(self) -> Result<Vec<Spanned<Value>>, Self>

Ok(inner) if self is an array like [1, 2, 3], otherwise Err(self)

Source

pub fn into_object(self) -> Result<Map<Spanned<String>, Spanned<Value>>, Self>

Ok(inner) if self is an object like {"a": 1, "b": 2}, otherwise Err(self)

Source

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

A human-readable representation of the type of this value

Trait Implementations§

Source§

impl Debug for Value

Source§

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

Formats the value using the given formatter. 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

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

Source§

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

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

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