pub struct Dynamic(_);
Expand description
A Rust value that has been wrapped for use in the virtual machine.
Implementations§
source§impl Dynamic
impl Dynamic
sourcepub fn new<T: DynamicValue + 'static>(value: T) -> Self
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.
sourcepub fn kind(&self) -> Symbol
pub fn kind(&self) -> Symbol
Returns the result of DynamicValue::kind()
for the wrapped value.
sourcepub fn inner<T: DynamicValue>(&self) -> Option<&T>
pub fn inner<T: DynamicValue>(&self) -> Option<&T>
Returns a reference to the contained value, if the contained type is
T
.
sourcepub fn try_into_inner<T: DynamicValue>(self) -> Result<T, Self>
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.
sourcepub fn into_inner<T: DynamicValue + Clone>(self) -> Result<T, Self>
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.
sourcepub fn is_truthy(&self) -> bool
pub fn is_truthy(&self) -> bool
Returns the result of DynamicValue::is_truthy()
for the wrapped
value.
sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Returns the result of DynamicValue::as_i64()
for the wrapped value.
sourcepub fn convert(&self, kind: &Symbol) -> Option<Value>
pub fn convert(&self, kind: &Symbol) -> Option<Value>
Returns the result of DynamicValue::convert()
for the wrapped value.
sourcepub fn is_falsey(&self) -> bool
pub fn is_falsey(&self) -> bool
Returns the inverse of DynamicValue::is_truthy()
for the wrapped
value.
sourcepub fn partial_eq(&self, other: &Value) -> Option<bool>
pub fn partial_eq(&self, other: &Value) -> Option<bool>
Returns the result of DynamicValue::partial_eq()
for the wrapped
value.
sourcepub fn partial_cmp(&self, other: &Value) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Value) -> Option<Ordering>
Returns the result of DynamicValue::partial_cmp()
for the wrapped
value.
sourcepub fn checked_add(
&self,
other: &Value,
is_reverse: bool
) -> Result<Option<Value>, FaultKind>
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.
sourcepub fn checked_sub(
&self,
other: &Value,
is_reverse: bool
) -> Result<Option<Value>, FaultKind>
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.
sourcepub fn checked_mul(
&self,
other: &Value,
is_reverse: bool
) -> Result<Option<Value>, FaultKind>
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.
sourcepub fn checked_div(
&self,
other: &Value,
is_reverse: bool
) -> Result<Option<Value>, FaultKind>
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.
sourcepub fn call(
&mut self,
name: &Symbol,
args: PoppedValues<'_>
) -> Result<Value, FaultKind>
pub fn call( &mut self, name: &Symbol, args: PoppedValues<'_> ) -> Result<Value, FaultKind>
Invokes DynamicValue::call
with the given parameters.
sourcepub fn to_source(&self) -> Option<String>
pub fn to_source(&self) -> Option<String>
Returns the result of DynamicValue::to_source()
for the wrapped
value.