RantValue

Enum RantValue 

Source
pub enum RantValue {
    String(RantString),
    Float(f64),
    Int(i64),
    Boolean(bool),
    Function(RantFunctionHandle),
    List(RantListHandle),
    Tuple(RantTupleHandle),
    Map(RantMapHandle),
    Range(RantRange),
    Selector(RantSelectorHandle),
    Nothing,
}
Expand description

A dynamically-typed Rant value.

§Cloning

Calling clone() on a by-ref Rant value type (such as list) will only clone its handle; both copies will point to the same contents.

If you want to shallow-copy a by-ref value, use the shallow_copy method instead.

Variants§

§

String(RantString)

A Rant value of type string. Passed by-value.

§

Float(f64)

A Rant value of type float. Passed by-value.

§

Int(i64)

A Rant value of type int. Passed by-value.

§

Boolean(bool)

A Rant value of type bool. Passed by-value.

§

Function(RantFunctionHandle)

A Rant value of type function. Passed by-reference.

§

List(RantListHandle)

A Rant value of type list. Passed by-reference.

§

Tuple(RantTupleHandle)

A Rant value of type tuple. Passed by-reference.

§

Map(RantMapHandle)

A Rant value of type map. Passed by-reference.

§

Range(RantRange)

A Rant value of type range. Passed by-value.

§

Selector(RantSelectorHandle)

A Rant value of type selector. Passed by-value.

§

Nothing

A Rant unit value of type nothing. Passed by-value.

Implementations§

Source§

impl RantValue

Source

pub const NAN: Self

Not a Number (NaN).

Source

pub const INFINITY: Self

Positive infinity.

Source

pub const NEG_INFINITY: Self

Negative infinity.

Source

pub const MIN_FLOAT: Self

The lowest possible finite value for the float type.

Source

pub const MAX_FLOAT: Self

The highest possible finite value for the float type.

Source

pub const EPSILON: Self

The smallest possible float value greater than zero.

Source

pub const MIN_INT: Self

The lowest possible value for the int type.

Source

pub const MAX_INT: Self

The highest possible value for the int type.

Source

pub fn is_nothing(&self) -> bool

Returns true if the value is of type nothing.

Source

pub fn is_nan(&self) -> bool

Returns true if the value is NaN (Not a Number).

Source

pub fn is_callable(&self) -> bool

Returns true if the value is callable (e.g. a function).

Source§

impl RantValue

Source

pub fn from_func<P: FromRantArgs, F: 'static + Fn(&mut VM<'_>, P) -> Result<(), RuntimeError>>( func: F, ) -> Self

Source

pub fn to_bool(&self) -> bool

Interprets this value as a boolean value according to Rant’s truthiness rules.

Types are converted as follows:

  1. bool returns itself.
  2. int returns true for any non-zero value; otherwise, false.
  3. float returns true for any normal value; otherwise, false.
  4. empty returns false.
  5. Collections that can be zero-length (string, list, map, range) return true if their length is nonzero; otherwise, false.
  6. All other types return true.
Source

pub fn into_bool_value(self) -> Self

Converts to a Rant bool value.

Source

pub fn into_int_value(self) -> Self

Converts to a Rant int value (or empty if the conversion fails).

Source

pub fn into_float_value(self) -> Self

Converts to a Rant float value (or empty if the conversion fails).

Source

pub fn into_string_value(self) -> Self

Converts to a Rant string value.

Source

pub fn into_list_value(self) -> Self

Converts to a Rant list value.

Source

pub fn into_tuple_value(self) -> Self

Converts to a Rant tuple value.

Source

pub fn len(&self) -> usize

Gets the length of the value.

Source

pub fn is_empty(&self) -> bool

Returns true if the length of the value is 0.

Source

pub fn reversed(&self) -> Self

Source

pub fn shallow_copy(&self) -> Self

Returns a shallow copy of the value.

Source

pub fn get_type(&self) -> RantValueType

Gets the Rant type associated with the value.

Source

pub fn type_name(&self) -> &'static str

Gets the type name of the value.

Source

pub fn slice_get(&self, slice: &Slice) -> ValueSliceResult

Source

pub fn slice_set( &mut self, slice: &Slice, val: RantValue, ) -> ValueSliceSetResult

Source

pub fn is_indexable(&self) -> bool

Indicates whether the value can be indexed into.

Source

pub fn index_get(&self, index: i64) -> ValueIndexResult

Attempts to get a value by index.

Source

pub fn index_set(&mut self, index: i64, val: RantValue) -> ValueIndexSetResult

Attempts to set a value by index.

Source

pub fn key_get(&self, key: &str) -> ValueKeyResult

Attempts to get a value by key.

Source

pub fn key_set(&mut self, key: &str, val: RantValue) -> ValueKeySetResult

Attempts to set a value by key.

Source§

impl RantValue

Source

pub fn pow(self, exponent: Self) -> ValueResult<Self>

Raises self to the exponent power.

Source

pub fn abs(self) -> ValueResult<Self>

Calculates the absolute value.

Source

pub fn and(self, rhs: RantValue) -> Self

Calculates the logical AND.

Source

pub fn or(self, rhs: RantValue) -> Self

Calculates the logical OR.

Source

pub fn xor(self, rhs: RantValue) -> Self

Calculates the logical XOR.

Trait Implementations§

Source§

impl Add for RantValue

Source§

type Output = RantValue

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for RantValue

Source§

fn clone(&self) -> RantValue

Returns a duplicate 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 Debug for RantValue

Source§

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

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

impl Default for RantValue

Source§

fn default() -> Self

Gets the default RantValue (empty).

Source§

impl Display for RantValue

Source§

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

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

impl Div for RantValue

Source§

type Output = Result<RantValue, ValueError>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<'a> FromIterator<&'a RantValue> for RantTuple

Source§

fn from_iter<T: IntoIterator<Item = &'a RantValue>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<RantValue> for RantList

Source§

fn from_iter<T: IntoIterator<Item = RantValue>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<RantValue> for RantTuple

Source§

fn from_iter<T: IntoIterator<Item = RantValue>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromRant for RantValue

Source§

fn from_rant(v: RantValue) -> RantValue

Converts from a RantValue.
Source§

fn is_optional_param_type() -> bool

Returns true if the type can be used to represent an optional Rant parameter in native functions; otherwise, false.
Source§

impl IntoRant for RantValue

Source§

fn into_rant(self) -> RantValue

Converts to a RantValue.
Source§

impl Mul for RantValue

Source§

type Output = RantValue

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for RantValue

Source§

type Output = RantValue

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Not for RantValue

Source§

type Output = RantValue

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl PartialEq for RantValue

Source§

fn eq(&self, other: &Self) -> 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 PartialOrd for RantValue

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Rem for RantValue

Source§

type Output = Result<RantValue, ValueError>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl Sub for RantValue

Source§

type Output = RantValue

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl TryFromRant for RantValue

Source§

fn try_from_rant(val: RantValue) -> Result<RantValue, ValueError>

Convert from a RantValue.
Source§

fn is_optional_param_type() -> bool

Returns true if the type can be used to represent an optional Rant parameter in native functions; otherwise, false.
Source§

impl TryIntoRant for RantValue

Source§

fn try_into_rant(self) -> Result<RantValue, ValueError>

Attempts to convert to a RantValue.
Source§

impl Eq for RantValue

Auto Trait Implementations§

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRantArgs for T
where T: TryFromRant,

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,

Source§

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§

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

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V