pub struct Value {
pub pos: usize,
pub kind: ValueKind,
}Expand description
The Value struct maintains both the position where this value is used and its kind. Maintaining the position is useful because it can be used to produce good error messages.
Fields§
§pos: usize§kind: ValueKindImplementations§
Source§impl Value
impl Value
Sourcepub fn add(&self, other: &Value, pos: usize) -> Result<Value, Error>
pub fn add(&self, other: &Value, pos: usize) -> Result<Value, Error>
This function takes the current value and a reference to another value and adds them together. Note that this function does not take ownership of either value. Instead, it creates a new value.
§Arguments
other - The other value to add.
pos - The position where this operation was called.
Sourcepub fn sub(&self, other: &Value, pos: usize) -> Result<Value, Error>
pub fn sub(&self, other: &Value, pos: usize) -> Result<Value, Error>
This function takes the current value and a reference to another value and subtracts them. Note that this function does not take ownership of either value. Instead, it creates a new value.
§Arguments
other - The other value to subtract.
pos - The position where this operation was called.
Sourcepub fn mul(&self, other: &Value, pos: usize) -> Result<Value, Error>
pub fn mul(&self, other: &Value, pos: usize) -> Result<Value, Error>
This function takes the current value and a reference to another value and mutliplies them. Note that this function does not take ownership of either value. Instead, it creates a new value.
§Arguments
other - The other value to multiply.
pos - The position where this operation was called.
Sourcepub fn div(&self, other: &Value, pos: usize) -> Result<Value, Error>
pub fn div(&self, other: &Value, pos: usize) -> Result<Value, Error>
This function takes the current value and a reference to another value and divides them. Note that this function does not take ownership of either value. Instead, it creates a new value.
§Arguments
other - The other value to divide.
pos - The position where this operation was called.
Sourcepub fn lt(&self, other: &Value, pos: usize) -> Result<Value, Error>
pub fn lt(&self, other: &Value, pos: usize) -> Result<Value, Error>
This function takes the current value and a reference to another value and returns if the current value is less than the second one. Note that this function does not consume either value.
§Arguments
other - The other value to compare.
pos - The position where this operation was called.
Sourcepub fn lte(&self, other: &Value, pos: usize) -> Result<Value, Error>
pub fn lte(&self, other: &Value, pos: usize) -> Result<Value, Error>
This function takes the current value and a reference to another value and returns if the current value is less than or equal to the second one. Note that this function does not consume either value.
§Arguments
other - The other value to compare.
pos - The position where this operation was called.
Sourcepub fn gt(&self, other: &Value, pos: usize) -> Result<Value, Error>
pub fn gt(&self, other: &Value, pos: usize) -> Result<Value, Error>
This function takes the current value and a reference to another value and returns if the current value is greater than the second one. Note that this function does not consume either value.
§Arguments
other - The other value to compare.
pos - The position where this operation was called.
Sourcepub fn gte(&self, other: &Value, pos: usize) -> Result<Value, Error>
pub fn gte(&self, other: &Value, pos: usize) -> Result<Value, Error>
This function takes the current value and a reference to another value and returns if the current value is greater than or equal to the second one. Note that this function does not consume either value.
§Arguments
other - The other value to compare.
pos - The position where this operation was called.
Sourcepub fn equal(&self, other: &Value, pos: usize) -> Value
pub fn equal(&self, other: &Value, pos: usize) -> Value
This function takes the current value and a reference to another value and returns if the current value is equal to the second one. Note that this function does not consume either value.
§Arguments
other - The other value to compare.
pos - The position where this operation was called.
Sourcepub fn not_equal(&self, other: &Value, pos: usize) -> Value
pub fn not_equal(&self, other: &Value, pos: usize) -> Value
This function takes the current value and a reference to another value and returns if the current value is not equal to the second one. Note that this function does not consume either value.
§Arguments
other - The other value to compare.
pos - The position where this operation was called.
Sourcepub fn is_truthy(&self) -> bool
pub fn is_truthy(&self) -> bool
This function takes the current value and returns if it is “truthy”. This can mean different things for differet values. For ints, it is whether it is not 0. For floats, it is whether it is not NAN, infinite, and not 0. For strings, it is whether it is not empty. Every other value is considered to be false.
Trait Implementations§
Source§impl From<Token> for Value
Converts a token into a value. This is used by the Code struct when generating the vector of values.
impl From<Token> for Value
Converts a token into a value. This is used by the Code struct when generating the vector of values.