Trait budvm::DynamicValue

source ·
pub trait DynamicValue: Send + Sync + Debug + 'static {
Show 13 methods // Required methods fn is_truthy(&self) -> bool; fn kind(&self) -> Symbol; // Provided methods fn as_i64(&self) -> Option<i64> { ... } fn convert(&self, kind: &Symbol) -> Option<Value> { ... } fn partial_eq(&self, other: &Value) -> Option<bool> { ... } fn partial_cmp(&self, other: &Value) -> Option<Ordering> { ... } fn checked_add( &self, other: &Value, is_reverse: bool ) -> Result<Option<Value>, FaultKind> { ... } fn checked_sub( &self, other: &Value, is_reverse: bool ) -> Result<Option<Value>, FaultKind> { ... } fn checked_mul( &self, other: &Value, is_reverse: bool ) -> Result<Option<Value>, FaultKind> { ... } fn checked_div( &self, other: &Value, is_reverse: bool ) -> Result<Option<Value>, FaultKind> { ... } fn call( &self, name: &Symbol, args: &mut PoppedValues<'_> ) -> Result<Value, FaultKind> { ... } fn to_source(&self) -> Option<String> { ... } fn hash<H>(&self, state: &mut H) -> bool where H: Hasher { ... }
}
Expand description

A type that can be used in the virtual machine using Value::dynamic.

Required Methods§

source

fn is_truthy(&self) -> bool

Returns true if the value contained is truthy. See Value::is_truthy() for examples of what this means for primitive types.

source

fn kind(&self) -> Symbol

Returns a unique string identifying this type. This returned string will be wrapped in ValueKind::Dynamic when Value::kind() is invoked on a dynamic value.

This value does not influence the virtual machine’s behavior. The virtual machine uses this string only when creating error messages.

Provided Methods§

source

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

Returns this value as an i64, if possible.

Implementhing this function enables this type to be used in integer operations such as bitwise operations.

source

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

Converts this value to the given kind, if possible.

If this function returns None, the virtual machine will return a fault from the conversion operation.

source

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

Returns true if self and other are considered equal. Returns false if self and other are able to be compared but are not equal. Returns None if the values are unable to be compared.

When evaluating left = right with dynamic values, if left.partial_eq(right) returns None, right.partial_eq(left) will be attempted before returning false.

source

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

Returns the relative ordering of self and other, if a comparison is able to be made. If the types cannot be compared, this function should return None.

When evaluating a comparison such as left < right with dynamic values, if left.partial_cmp(right) returns None, right.partial_cmp(left).map(Ordering::reverse) will be attempted before returning false.

source

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

Attempts to compute the result adding self and other.

While addition is normally an associative operation, is_reverse allows determining if self is the left operand or the right operand to the operation.

If is_reverse is false, the operation being requested is self + other. If is_reverse is true, the operation being requested is other + self.

source

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

Attempts to compute the result subtracting self and other.

If is_reverse is false, the operation being requested is self - other. If is_reverse is true, the operation being requested is other - self.

source

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

Attempts to compute the result multiplying self and other.

While multiplication is normally an associative operation, is_reverse allows determining if self is the left operand or the right operand to the operation.

If is_reverse is false, the operation being requested is self * other. If is_reverse is true, the operation being requested is other * self.

source

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

Attempts to compute the result dividing self and other.

If is_reverse is false, the operation being requested is self / other. If is_reverse is true, the operation being requested is other / self.

source

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

Calls a function by name with args.

source

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

Returns this value as represented in source, if possible.

source

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

Hashes the contents of this value. Returns true if this operation is supported.

To allow the Value type to implement Hash but contain values that don’t implement Hash, this is not a trait that is required to implement.

This allows safe collection types to be written, which check before key insertion that the value can be hashed and returns an error rather than panicking in the call to hash.

Implementations on Foreign Types§

source§

impl DynamicValue for String

source§

fn is_truthy(&self) -> bool

source§

fn kind(&self) -> Symbol

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

Implementors§

source§

impl DynamicValue for List

source§

impl<State> DynamicValue for HashMap<State>where State: BuildHasher + Debug + Clone + Send + Sync + 'static,