pub enum Value {
Integer(i64),
Float(f64),
Boolean(bool),
String(String),
Function(Function),
Null,
}
Expand description
The Value
enum represents a data type that can be stored in an Environment
. Each
type contains the data it represents (e.g. a Value::Integer
contains an i64
).
There are 6 types of values: Integer
, Float
, Boolean
, String
, Function
and
Null
.
Variants§
Integer(i64)
Float(f64)
Boolean(bool)
String(String)
Function(Function)
Null
The Null
variant is used to represent the absence of a value. It is used to
represent the result of an expression that doesn’t return anything (e.g. a
function call that doesn’t return anything).
Implementations§
Source§impl Value
impl Value
Sourcepub fn variant_name(&self) -> &'static str
pub fn variant_name(&self) -> &'static str
Returns the display name of the variant of the Value
enum.
Sourcepub fn cast_to_boolean(&self) -> Result<Self, Error>
pub fn cast_to_boolean(&self) -> Result<Self, Error>
This method converts any Value
to a Value::Boolean
. It returns an error if
the conversion is not possible.
Sourcepub fn cast_to_string(&self) -> Self
pub fn cast_to_string(&self) -> Self
This method converts any Value
to a Value::Integer
. It returns an error if
the conversion is not possible. (For now, all conversions are possible.)
pub fn eq(&self, other: &Self) -> Result<Self, Error>
pub fn ne(&self, other: &Self) -> Result<Self, Error>
pub fn lt(&self, other: &Self) -> Result<Self, Error>
pub fn le(&self, other: &Self) -> Result<Self, Error>
pub fn gt(&self, other: &Self) -> Result<Self, Error>
pub fn ge(&self, other: &Self) -> Result<Self, Error>
Sourcepub fn not(&self) -> Result<Self, Error>
pub fn not(&self) -> Result<Self, Error>
This method returns the logical negation of a Value::Boolean
. It returns an
error for all other types.
Sourcepub fn and(&self, other: &Self) -> Result<Self, Error>
pub fn and(&self, other: &Self) -> Result<Self, Error>
This method returns the logical and of two Value::Boolean
s. It returns an error
for all other types.
Sourcepub fn or(&self, other: &Self) -> Result<Self, Error>
pub fn or(&self, other: &Self) -> Result<Self, Error>
This method returns the logical or of two Value::Boolean
s. It returns an error
for all other types.
pub fn sub(&self, other: &Self) -> Result<Self, Error>
pub fn mul(&self, other: &Self) -> Result<Self, Error>
pub fn rem(&self, other: &Self) -> Result<Self, Error>
Sourcepub fn add(&self, other: &Self) -> Result<Self, Error>
pub fn add(&self, other: &Self) -> Result<Self, Error>
This method returns the sum of two Value
s. It returns an error if the operation
is not possible.
Trait Implementations§
Source§impl Display for Value
Implementing the Display
trait for Value
allows for the pretty printing of
values.
impl Display for Value
Implementing the Display
trait for Value
allows for the pretty printing of
values.