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
impl RantValue
Sourcepub const NEG_INFINITY: Self
pub const NEG_INFINITY: Self
Negative infinity.
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).
Source§impl 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:
boolreturns itself.intreturnstruefor any non-zero value; otherwise,false.floatreturnstruefor any normal value; otherwise,false.emptyreturnsfalse.- Collections that can be zero-length (
string,list,map,range) returntrueif 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.
Source§impl 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§
Source§impl<'a> FromIterator<&'a RantValue> for RantTuple
impl<'a> FromIterator<&'a RantValue> for RantTuple
Source§impl FromIterator<RantValue> for RantList
impl FromIterator<RantValue> for RantList
Source§impl FromIterator<RantValue> for RantTuple
impl FromIterator<RantValue> for RantTuple
Source§impl PartialOrd for RantValue
impl PartialOrd for RantValue
Source§impl TryFromRant for RantValue
impl TryFromRant for RantValue
Source§fn try_from_rant(val: RantValue) -> Result<RantValue, ValueError>
fn try_from_rant(val: RantValue) -> Result<RantValue, ValueError>
RantValue.Source§fn is_optional_param_type() -> bool
fn is_optional_param_type() -> bool
true if the type can be used to represent an optional Rant parameter in native functions; otherwise, false.Source§impl TryIntoRant for RantValue
impl TryIntoRant for RantValue
Source§fn try_into_rant(self) -> Result<RantValue, ValueError>
fn try_into_rant(self) -> Result<RantValue, ValueError>
RantValue.impl Eq for RantValue
Auto Trait Implementations§
impl !Freeze for RantValue
impl !RefUnwindSafe for RantValue
impl !Send for RantValue
impl !Sync for RantValue
impl Unpin for RantValue
impl !UnwindSafe for RantValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.