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
sourceimpl RantValue
impl RantValue
sourcepub const NEG_INFINITY: Self = Self::Float(f64::NEG_INFINITY)
pub const NEG_INFINITY: Self = Self::Float(f64::NEG_INFINITY)
Negative infinity.
sourcepub const MIN_FLOAT: Self = Self::Float(f64::MIN)
pub const MIN_FLOAT: Self = Self::Float(f64::MIN)
The lowest possible finite value for the float
type.
sourcepub const MAX_FLOAT: Self = Self::Float(f64::MAX)
pub const MAX_FLOAT: Self = Self::Float(f64::MAX)
The highest possible finite value for the float
type.
sourcepub const EPSILON: Self = Self::Float(f64::EPSILON)
pub const EPSILON: Self = Self::Float(f64::EPSILON)
The smallest possible float
value greater than zero.
sourcepub fn is_nothing(&self) -> bool
pub fn is_nothing(&self) -> bool
Returns true if the value is of type nothing
.
sourcepub fn is_callable(&self) -> bool
pub fn is_callable(&self) -> bool
Returns true if the value is callable (e.g. a function).
sourceimpl RantValue
impl RantValue
pub fn from_func<P: FromRantArgs, F: 'static + Fn(&mut VM<'_>, P) -> Result<(), RuntimeError>>(
func: F
) -> Self
sourcepub fn to_bool(&self) -> bool
pub fn to_bool(&self) -> bool
Interprets this value as a boolean value according to Rant’s truthiness rules.
Types are converted as follows:
bool
returns itself.int
returnstrue
for any non-zero value; otherwise,false
.float
returnstrue
for any normal value; otherwise,false
.empty
returnsfalse
.- Collections that can be zero-length (
string
,list
,map
,range
) returntrue
if their length is nonzero; otherwise,false
. - All other types return
true
.
sourcepub fn into_bool_value(self) -> Self
pub fn into_bool_value(self) -> Self
Converts to a Rant bool
value.
sourcepub fn into_int_value(self) -> Self
pub fn into_int_value(self) -> Self
Converts to a Rant int
value (or empty
if the conversion fails).
sourcepub fn into_float_value(self) -> Self
pub fn into_float_value(self) -> Self
Converts to a Rant float
value (or empty
if the conversion fails).
sourcepub fn into_string_value(self) -> Self
pub fn into_string_value(self) -> Self
Converts to a Rant string
value.
sourcepub fn into_list_value(self) -> Self
pub fn into_list_value(self) -> Self
Converts to a Rant list
value.
sourcepub fn into_tuple_value(self) -> Self
pub fn into_tuple_value(self) -> Self
Converts to a Rant tuple
value.
pub fn reversed(&self) -> Self
sourcepub fn shallow_copy(&self) -> Self
pub fn shallow_copy(&self) -> Self
Returns a shallow copy of the value.
sourcepub fn get_type(&self) -> RantValueType
pub fn get_type(&self) -> RantValueType
Gets the Rant type associated with the value.
pub fn slice_get(&self, slice: &Slice) -> ValueSliceResult
pub fn slice_set(
&mut self,
slice: &Slice,
val: RantValue
) -> ValueSliceSetResult
sourcepub fn is_indexable(&self) -> bool
pub fn is_indexable(&self) -> bool
Indicates whether the value can be indexed into.
sourcepub fn index_get(&self, index: i64) -> ValueIndexResult
pub fn index_get(&self, index: i64) -> ValueIndexResult
Attempts to get a value by index.
sourcepub fn index_set(&mut self, index: i64, val: RantValue) -> ValueIndexSetResult
pub fn index_set(&mut self, index: i64, val: RantValue) -> ValueIndexSetResult
Attempts to set a value by index.
sourcepub fn key_get(&self, key: &str) -> ValueKeyResult
pub fn key_get(&self, key: &str) -> ValueKeyResult
Attempts to get a value by key.
sourcepub fn key_set(&mut self, key: &str, val: RantValue) -> ValueKeySetResult
pub fn key_set(&mut self, key: &str, val: RantValue) -> ValueKeySetResult
Attempts to set a value by key.
sourceimpl RantValue
impl RantValue
sourcepub fn pow(self, exponent: Self) -> ValueResult<Self>
pub fn pow(self, exponent: Self) -> ValueResult<Self>
Raises self
to the exponent
power.
sourcepub fn abs(self) -> ValueResult<Self>
pub fn abs(self) -> ValueResult<Self>
Calculates the absolute value.
Trait Implementations
sourceimpl<'a> FromIterator<&'a RantValue> for RantTuple
impl<'a> FromIterator<&'a RantValue> for RantTuple
sourcefn from_iter<T: IntoIterator<Item = &'a RantValue>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = &'a RantValue>>(iter: T) -> Self
Creates a value from an iterator. Read more
sourceimpl FromIterator<RantValue> for RantList
impl FromIterator<RantValue> for RantList
sourcefn from_iter<T: IntoIterator<Item = RantValue>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = RantValue>>(iter: T) -> Self
Creates a value from an iterator. Read more
sourceimpl FromIterator<RantValue> for RantTuple
impl FromIterator<RantValue> for RantTuple
sourcefn from_iter<T: IntoIterator<Item = RantValue>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = RantValue>>(iter: T) -> Self
Creates a value from an iterator. Read more
sourceimpl PartialOrd<RantValue> for RantValue
impl PartialOrd<RantValue> for RantValue
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl TryFromRant for RantValue
impl TryFromRant for RantValue
sourcefn try_from_rant(val: RantValue) -> Result<RantValue, ValueError>
fn try_from_rant(val: RantValue) -> Result<RantValue, ValueError>
Convert from a RantValue
.
sourcefn is_optional_param_type() -> bool
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
.
sourceimpl TryIntoRant for RantValue
impl TryIntoRant for RantValue
sourcefn try_into_rant(self) -> Result<RantValue, ValueError>
fn try_into_rant(self) -> Result<RantValue, ValueError>
Attempts to convert to a RantValue
.
impl Eq for RantValue
Auto Trait Implementations
impl !RefUnwindSafe for RantValue
impl !Send for RantValue
impl !Sync for RantValue
impl Unpin for RantValue
impl !UnwindSafe for RantValue
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more