Struct budvm::Dynamic

source ·
pub struct Dynamic(_);
Expand description

A Rust value that has been wrapped for use in the virtual machine.

Implementations§

source§

impl Dynamic

source

pub fn new<T: DynamicValue + 'static>(value: T) -> Self

Returns a new instance, wrapping value.

This function causes two allocations: Arc::new() and Box::new(). While Arc<dyn T> could be used for only one allocation, it uses a “fat pointer” which is double the size of a standard pointer. By using Arc<Box<dyn T>>, the Box<dyn T> becomes the fat pointer and the Arc remains a normal pointer. The net effect is that the Value enum is able to stay smaller due to this extra allocation.

source

pub fn kind(&self) -> Symbol

Returns the result of DynamicValue::kind() for the wrapped value.

source

pub fn type_id(&self) -> TypeId

Returns the TypeId of the wrapped type.

source

pub fn inner<T: DynamicValue>(&self) -> Option<&T>

Returns a reference to the contained value, if the contained type is T.

source

pub fn try_into_inner<T: DynamicValue>(self) -> Result<T, Self>

Attempts to unwrap the value. If there is more than one reference to this value, or T does not match the contained type, Err(self) will be returned.

source

pub fn into_inner<T: DynamicValue + Clone>(self) -> Result<T, Self>

Returns the contained value if T is the contained type. If the value contains another type, Err(self) will be returned. Otherwise, the inner value will be returned.

Because dynamic values are cheaply cloned by wrapping the value in an 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 is_truthy(&self) -> bool

Returns the result of DynamicValue::is_truthy() for the wrapped value.

source

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

Returns the result of DynamicValue::as_i64() for the wrapped value.

source

pub fn convert(&self, kind: &Symbol) -> Option<Value>

Returns the result of DynamicValue::convert() for the wrapped value.

source

pub fn is_falsey(&self) -> bool

Returns the inverse of DynamicValue::is_truthy() for the wrapped value.

source

pub fn partial_eq(&self, other: &Value) -> Option<bool>

Returns the result of DynamicValue::partial_eq() for the wrapped value.

source

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

Returns the result of DynamicValue::partial_cmp() for the wrapped value.

source

pub fn checked_add( &self, other: &Value, is_reverse: bool ) -> Result<Option<Value>, FaultKind>

Returns the result of DynamicValue::checked_add() for the wrapped value.

source

pub fn checked_sub( &self, other: &Value, is_reverse: bool ) -> Result<Option<Value>, FaultKind>

Returns the result of DynamicValue::checked_sub() for the wrapped value.

source

pub fn checked_mul( &self, other: &Value, is_reverse: bool ) -> Result<Option<Value>, FaultKind>

Returns the result of DynamicValue::checked_mul() for the wrapped value.

source

pub fn checked_div( &self, other: &Value, is_reverse: bool ) -> Result<Option<Value>, FaultKind>

Returns the result of DynamicValue::checked_div() for the wrapped value.

source

pub fn call( &mut self, name: &Symbol, args: PoppedValues<'_> ) -> Result<Value, FaultKind>

Invokes DynamicValue::call with the given parameters.

source

pub fn to_source(&self) -> Option<String>

Returns the result of DynamicValue::to_source() for the wrapped value.

source

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

Returns the result of DynamicValue::hash() for the wrapped value.

Trait Implementations§

source§

impl Clone for Dynamic

source§

fn clone(&self) -> Dynamic

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 Dynamic

source§

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

Formats the value using the given formatter. Read more
source§

impl Display for Dynamic

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.