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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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>

source

pub fn native_fn(function: impl NativeFn<T> + 'static) -> Self

Creates a value for a native function.

source

pub fn wrapped_fn<const CTX: bool, Args, F>(fn_to_wrap: F) -> Self
where FnWrapper<Args, F, CTX>: NativeFn<T> + 'static,

Creates a wrapped function.

Calling this method is equivalent to wrapping 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.

source

pub const fn void() -> Self

Creates a void value (an empty tuple).

source

pub fn opaque_ref(value: impl Any + Debug + PartialEq) -> Self

Creates a reference to a native variable.

source

pub fn value_type(&self) -> ValueType

Returns the type of this value.

source

pub fn is_void(&self) -> bool

Checks if this value is void (an empty tuple).

source

pub fn is_function(&self) -> bool

Checks if this value is a function.

Trait Implementations§

source§

impl<T: Clone> Clone for Value<T>

source§

fn clone(&self) -> Value<T>

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<T: Debug> Debug for Value<T>

source§

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

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

impl<T: Display> Display for Value<T>

source§

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

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

impl<T: Clone> From<&Value<T>> for Value<T>

source§

fn from(reference: &Value<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Object<T>> for Value<T>

source§

fn from(object: Object<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Tuple<T>> for Value<T>

source§

fn from(tuple: Tuple<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Vec<Value<T>>> for Value<T>

source§

fn from(elements: Vec<Self>) -> Self

Converts to this type from the input type.
source§

impl<T> IntoEvalResult<T> for Value<T>

source§

fn into_eval_result(self) -> Result<Value<T>, ErrorOutput>

Performs the conversion.
source§

impl<T: PartialEq> PartialEq for Value<T>

source§

fn eq(&self, rhs: &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<T> TryFromValue<T> for Value<T>

source§

fn try_from_value(value: Value<T>) -> Result<Self, FromValueError>

Attempts to convert 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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where 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 T
where 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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.