Enum endbasic_core::ast::Value
source · Expand description
Represents an evaluated value.
Variants§
Boolean(bool)
A boolean value.
Double(f64)
A double-precision floating point value.
Integer(i32)
An integer value.
Text(String)
A string value.
Implementations§
source§impl Value
impl Value
sourcepub fn as_vartype(&self) -> VarType
pub fn as_vartype(&self) -> VarType
Returns the type of the value as a VarType
.
sourcepub fn to_text(self) -> String
pub fn to_text(self) -> String
Consumes the value and converts it to a string value. This is slightly different from the
Display
implementation because strings aren’t double-quoted.
The output of this function is used anything a value is converted to a string, say as the
output of PRINT
.
This is not named to_string
to prevent confusion with the behavior of a traditional
method named like that, and to avoid conflicts with the Display
implementation.
source§impl Value
impl Value
sourcepub fn parse_as<T: Into<String>>(vtype: VarType, s: T) -> Result<Value, Error>
pub fn parse_as<T: Into<String>>(vtype: VarType, s: T) -> Result<Value, Error>
Parses a string s
and constructs a Value
that matches a given VarType
.
sourcepub fn as_i32(&self) -> Result<i32, Error>
pub fn as_i32(&self) -> Result<i32, Error>
Reinterprets this value as an i32
and fails if the conversion is not possible.
sourcepub fn as_f64(&self) -> Result<f64, Error>
pub fn as_f64(&self) -> Result<f64, Error>
Reinterprets this value as an f64
and fails if the conversion is not possible.
sourcepub fn maybe_cast(self, target: VarType) -> Result<Value, Error>
pub fn maybe_cast(self, target: VarType) -> Result<Value, Error>
Given a target
variable type, tries to convert the value to that type if they are
compatible or otherwise returns self.
Can return an error when the conversion is feasible but it is not possible, such as trying to cast a NaN to an integer.
sourcepub fn and(&self, other: &Self) -> Result<Self, Error>
pub fn and(&self, other: &Self) -> Result<Self, Error>
Performs a logical or bitwise “and” operation.
sourcepub fn or(&self, other: &Self) -> Result<Self, Error>
pub fn or(&self, other: &Self) -> Result<Self, Error>
Performs a logical or bitwise “or” operation.
sourcepub fn xor(&self, other: &Self) -> Result<Self, Error>
pub fn xor(&self, other: &Self) -> Result<Self, Error>
Performs a logical or bitwise “xor” operation.