Enum arithmetic_eval::Value
source · #[non_exhaustive]pub enum Value<T> {
Prim(T),
Bool(bool),
Function(Function<T>),
Tuple(Tuple<T>),
Object(Object<T>),
Ref(OpaqueRef),
}
Expand description
Values produced by expressions during their interpretation.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Prim(T)
Primitive value, such as a number. This does not include Boolean values, which are a separate variant.
Literals must necessarily map to primitive values, but there may be some primitive values not representable as literals.
Bool(bool)
Boolean value.
Function(Function<T>)
Function.
Tuple(Tuple<T>)
Tuple of zero or more values.
Object(Object<T>)
Object with zero or more named fields.
Ref(OpaqueRef)
Opaque reference to a native value.
Implementations§
source§impl<T> Value<T>
impl<T> Value<T>
sourcepub fn native_fn(function: impl NativeFn<T> + 'static) -> Self
pub fn native_fn(function: impl NativeFn<T> + 'static) -> Self
Creates a value for a native function.
sourcepub fn wrapped_fn<const CTX: bool, Args, F>(fn_to_wrap: F) -> Self
pub fn wrapped_fn<const CTX: bool, Args, F>(fn_to_wrap: F) -> Self
Creates a wrapped function.
Calling this method is equivalent to wrap
ping a function and calling
Self::native_fn()
on it. Thanks to type inference magic, the Rust compiler
will usually be able to extract the Args
type param from the function definition,
provided that type of function arguments and its return type are defined explicitly
or can be unequivocally inferred from the declaration.
sourcepub fn opaque_ref(value: impl Any + Debug + PartialEq) -> Self
pub fn opaque_ref(value: impl Any + Debug + PartialEq) -> Self
Creates a reference to a native variable.
sourcepub fn value_type(&self) -> ValueType
pub fn value_type(&self) -> ValueType
Returns the type of this value.
sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Checks if this value is a function.
Trait Implementations§
source§impl<T> IntoEvalResult<T> for Value<T>
impl<T> IntoEvalResult<T> for Value<T>
source§fn into_eval_result(self) -> Result<Value<T>, ErrorOutput>
fn into_eval_result(self) -> Result<Value<T>, ErrorOutput>
source§impl<T> TryFromValue<T> for Value<T>
impl<T> TryFromValue<T> for Value<T>
source§fn try_from_value(value: Value<T>) -> Result<Self, FromValueError>
fn try_from_value(value: Value<T>) -> Result<Self, FromValueError>
value
to a type supported by the function.Auto Trait Implementations§
impl<T> Freeze for Value<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Value<T>
impl<T> !Send for Value<T>
impl<T> !Sync for Value<T>
impl<T> Unpin for Value<T>where
T: Unpin,
impl<T> !UnwindSafe for Value<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)