Enum dust_lang::Value

source ·
pub enum Value {
    List(List),
    Map(Map),
    Function(Function),
    String(Arc<RwLock<String>>),
    Float(f64),
    Integer(i64),
    Boolean(bool),
    Option(Option<Box<Value>>),
}
Expand description

Dust value representation.

Every dust variable has a key and a Value. Variables are represented by storing them in a VariableMap. This means the map of variables is itself a value that can be treated as any other.

Variants§

§

List(List)

§

Map(Map)

§

Function(Function)

§

String(Arc<RwLock<String>>)

§

Float(f64)

§

Integer(i64)

§

Boolean(bool)

§

Option(Option<Box<Value>>)

Implementations§

source§

impl Value

source

pub fn string<T: Into<String>>(string: T) -> Self

source

pub fn type(&self) -> Type

source

pub fn none() -> Self

source

pub fn some(value: Value) -> Self

source

pub fn option(option: Option<Value>) -> Self

source

pub fn is_string(&self) -> bool

source

pub fn is_integer(&self) -> bool

source

pub fn is_float(&self) -> bool

source

pub fn is_number(&self) -> bool

source

pub fn is_boolean(&self) -> bool

source

pub fn is_list(&self) -> bool

source

pub fn is_option(&self) -> bool

source

pub fn is_none(&self) -> bool

source

pub fn is_map(&self) -> bool

source

pub fn is_function(&self) -> bool

source

pub fn as_string(&self) -> Result<RwLockReadGuard<'_, String>>

Borrows the value stored in self as &str, or returns Err if self is not a Value::String.

source

pub fn as_string_mut(&self) -> Result<RwLockWriteGuard<'_, String>>

Borrows the value stored in self as String, or returns Err if self is not a Value::String.

source

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

Copies the value stored in self as i64, or returns Err if self is not a Value::Int.

source

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

Copies the value stored in self as f64, or returns Err if self is not a Primitive::Float.

source

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

Copies the value stored in self as f64, or returns Err if self is not a Primitive::Float or Value::Int. Note that this method silently converts i64 to f64, if self is a Value::Int.

source

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

Copies the value stored in self as bool, or returns Err if self is not a Primitive::Boolean.

source

pub fn as_list(&self) -> Result<&List>

Borrows the value stored in self as Vec<Value>, or returns Err if self is not a Value::List.

source

pub fn into_inner_list(self) -> Result<List>

Takes ownership of the value stored in self as Vec<Value>, or returns Err if self is not a Value::List.

source

pub fn as_map(&self) -> Result<&Map>

Borrows the value stored in self as Vec<Value>, or returns Err if self is not a Value::Map.

source

pub fn as_function(&self) -> Result<&Function>

Borrows the value stored in self as Function, or returns Err if self is not a Value::Function.

source

pub fn as_option(&self) -> Result<&Option<Box<Value>>>

Returns Option, or returns Err if self is not a Value::Option.

source

pub fn as_none(&self) -> Result<()>

Returns (), or returns Err if self is not a Value::none().

Trait Implementations§

source§

impl Add for Value

§

type Output = Result<Value, Error>

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign for Value

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
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() -> Self

Returns the “default value” for a type. 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: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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 Div for Value

§

type Output = Result<Value, Error>

The resulting type after applying the / operator.
source§

fn div(self, other: Self) -> Self::Output

Performs the / operation. Read more
source§

impl From<&str> for Value

source§

fn from(string: &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 From<String> for Value

source§

fn from(string: String) -> Self

Converts to this type from the input type.
source§

impl From<Value> for Result<Value>

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Vec<Value>> for Value

source§

fn from(vec: Vec<Value>) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Value

source§

fn from(boolean: bool) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(float: f64) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Value

source§

fn from(int: i64) -> Self

Converts to this type from the input type.
source§

impl Mul for Value

§

type Output = Result<Value, Error>

The resulting type after applying the * operator.
source§

fn mul(self, other: Self) -> Self::Output

Performs the * operation. Read more
source§

impl Ord for Value

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Value

source§

fn eq(&self, other: &Self) -> 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: &Self) -> 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 Rem for Value

§

type Output = Result<Value, Error>

The resulting type after applying the % operator.
source§

fn rem(self, other: Self) -> Self::Output

Performs the % operation. Read more
source§

impl Serialize for Value

source§

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

Serialize this value into the given Serde serializer. Read more
source§

impl Sub for Value

§

type Output = Result<Value, Error>

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign for Value

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl TryFrom<Value> for String

§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for bool

§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for f64

§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Value> for i64

§

type Error = Error

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq 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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

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