Struct Value

Source
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: ValueKind

Implementations§

Source§

impl Value

Source

pub fn new(pos: usize, kind: ValueKind) -> Value

Constructs a new Value struct with the specified position and kind.

§Arguments

pos - The position where this value is created or called. kind - The value of this value.

Source§

impl Value

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

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

Formats the value using the given formatter. Read more
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.

Source§

fn from(token: Token) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

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

Source§

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>,

Source§

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.