Enum budvm::Value

source ·
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

source

pub fn dynamic(value: impl DynamicValue + 'static) -> Self

Returns a new value containing the Rust value provided.

source

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.

source

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.

source

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.

source

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

If this value is a Value::Integer, this function returns the contained value. Otherwise, None is returned.

source

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

If this value is a Value::Real, this function returns the contained value. Otherwise, None is returned.

source

pub fn convert<Env>( &self, kind: &ValueKind, environment: &Env ) -> Result<Self, FaultKind>where Env: Environment,

Converts this value to another kind, if possible.

source

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.

source

pub fn is_truthy(&self) -> bool

Returns true if the value is considered truthy.

value typecondition
Integervalue != 0
Booleanvalue is true
Voidalways false
source

pub fn is_falsey(&self) -> bool

Returns the inverse of is_truthy()

source

pub fn kind(&self) -> ValueKind

Returns the kind of the contained value.

source

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.

source

pub fn try_hash<H: Hasher>(&self, state: &mut H) -> bool

Attempts to compute a hash over this value. Returns true if the value contained supports hashing.

The state may be mutated even if the contained value does not contain a hashable value.

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() -> Self

Returns the “default value” for a type. 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<'a> From<&'a str> for Value

source§

fn from(str: &'a 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<T> From<T> for Valuewhere T: DynamicValue,

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(real: 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 FromIterator<Value> for List

source§

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

Creates a value from an iterator. Read more
source§

impl FromStack for Value

source§

fn from_value(value: Value) -> Result<Self, FaultKind>

Returns an instance constructing from the stack.
source§

impl Hash for Value

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<Value> 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 PartialEq<bool> for Value

source§

fn eq(&self, other: &bool) -> 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 PartialEq<f64> for Value

source§

fn eq(&self, rhs: &f64) -> 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 PartialEq<i64> for Value

source§

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

source§

fn partial_cmp(&self, right: &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 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.