pub enum Value {
Void,
Integer(i64),
Real(f64),
Boolean(bool),
Dynamic(Dynamic),
}
Expand description
A virtual machine value.
Variants§
Void
A value representing the lack of a value.
Integer(i64)
A signed 64-bit integer value.
Real(f64)
A real number value (64-bit floating point).
Boolean(bool)
A boolean representing true or false.
Dynamic(Dynamic)
A type exposed from Rust.
Implementations§
source§impl Value
impl Value
sourcepub fn dynamic(value: impl DynamicValue + 'static) -> Self
pub fn dynamic(value: impl DynamicValue + 'static) -> Self
Returns a new value containing the Rust value provided.
sourcepub fn as_dynamic<T: DynamicValue>(&self) -> Option<&T>
pub fn as_dynamic<T: DynamicValue>(&self) -> Option<&T>
Returns a reference to the contained value, if it was one originally
created with Value::dynamic()
. If the value isn’t a dynamic value or
T
is not the correct type, None will be returned.
sourcepub fn try_into_dynamic<T: DynamicValue>(self) -> Result<T, Self>
pub fn try_into_dynamic<T: DynamicValue>(self) -> Result<T, Self>
Returns the contained value if T
matches the contained type and this
is the final reference to the value. If the value contains another type
or additional references exist, Err(self)
will be returned. Otherwise,
the original value will be returned.
sourcepub fn into_dynamic<T: DynamicValue + Clone>(self) -> Result<T, Self>
pub fn into_dynamic<T: DynamicValue + Clone>(self) -> Result<T, Self>
Returns the contained value, if it was one originally created with
Value::dynamic()
and T
is the same type. If the value contains
another type, Err(self)
will be returned. Otherwise, the original
value will be returned.
Because dynamic values are cheaply cloned by wrapping the value in an
std::sync::Arc
, this method will return a clone if there are any
other instances that point to the same contained value. If this is the
final instance of this value, the contained value will be returned
without additional allocations.
sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
If this value is a Value::Integer
, this function returns the
contained value. Otherwise, None
is returned.
sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
If this value is a Value::Real
, this function returns the
contained value. Otherwise, None
is returned.
sourcepub fn convert<Env>(
&self,
kind: &ValueKind,
environment: &Env
) -> Result<Self, FaultKind>where
Env: Environment,
pub fn convert<Env>( &self, kind: &ValueKind, environment: &Env ) -> Result<Self, FaultKind>where Env: Environment,
Converts this value to another kind, if possible.
sourcepub fn try_convert_to_string<Env>(&self, env: &Env) -> Result<String, FaultKind>where
Env: Environment<String = String>,
pub fn try_convert_to_string<Env>(&self, env: &Env) -> Result<String, FaultKind>where Env: Environment<String = String>,
Tries to convert this value into a String.
This is a shorthand for calling convert()
and then into_dynamic()
on
the resulting value.
sourcepub fn is_truthy(&self) -> bool
pub fn is_truthy(&self) -> bool
Returns true if the value is considered truthy.
value type | condition |
---|---|
Integer | value != 0 |
Boolean | value is true |
Void | always false |
sourcepub fn is_falsey(&self) -> bool
pub fn is_falsey(&self) -> bool
Returns the inverse of is_truthy()
sourcepub fn implements_hash(&self) -> bool
pub fn implements_hash(&self) -> bool
Returns true if value contained supports hashing.
Using Hash
on a value that does not support hashing will not panic,
but unique hash values will not be generated.
Trait Implementations§
source§impl<T> From<T> for Valuewhere
T: DynamicValue,
impl<T> From<T> for Valuewhere T: DynamicValue,
source§impl FromIterator<Value> for List
impl FromIterator<Value> for List
source§impl PartialEq<Value> for Value
impl PartialEq<Value> for Value
source§impl PartialEq<bool> for Value
impl PartialEq<bool> for Value
source§impl PartialOrd<Value> for Value
impl PartialOrd<Value> for Value
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more