pub struct ConstValue { /* private fields */ }
Expand description
A constant value.
Implementations§
Source§impl ConstValue
impl ConstValue
Sourcepub fn tuple(values: Box<[ConstValue]>) -> ConstValue
pub fn tuple(values: Box<[ConstValue]>) -> ConstValue
Construct a new tuple constant value.
Sourcepub fn for_struct<const N: usize>(
hash: Hash,
fields: [ConstValue; N],
) -> Result<ConstValue, RuntimeError>
pub fn for_struct<const N: usize>( hash: Hash, fields: [ConstValue; N], ) -> Result<ConstValue, RuntimeError>
Construct a constant value for a struct.
Sourcepub fn as_integer<T>(&self) -> Result<T, RuntimeError>
pub fn as_integer<T>(&self) -> Result<T, RuntimeError>
Try to coerce the current value as the specified integer T
.
§Examples
let value = rune::to_const_value(u32::MAX)?;
assert_eq!(value.as_integer::<u64>()?, u32::MAX as u64);
assert!(value.as_integer::<i32>().is_err());
Sourcepub fn as_ordering(&self) -> Result<Ordering, RuntimeError>
pub fn as_ordering(&self) -> Result<Ordering, RuntimeError>
Coerce into Ordering
.
This gets a copy of the value.
Sourcepub fn as_ordering_mut(&mut self) -> Result<&mut Ordering, RuntimeError>
pub fn as_ordering_mut(&mut self) -> Result<&mut Ordering, RuntimeError>
Coerce into Ordering
.
This gets the value by mutable reference.
Sourcepub fn as_bool(&self) -> Result<bool, RuntimeError>
pub fn as_bool(&self) -> Result<bool, RuntimeError>
Coerce into bool
.
This gets a copy of the value.
Sourcepub fn as_bool_mut(&mut self) -> Result<&mut bool, RuntimeError>
pub fn as_bool_mut(&mut self) -> Result<&mut bool, RuntimeError>
Coerce into bool
.
This gets the value by mutable reference.
Sourcepub fn as_char(&self) -> Result<char, RuntimeError>
pub fn as_char(&self) -> Result<char, RuntimeError>
Coerce into char
.
This gets a copy of the value.
Sourcepub fn as_char_mut(&mut self) -> Result<&mut char, RuntimeError>
pub fn as_char_mut(&mut self) -> Result<&mut char, RuntimeError>
Coerce into char
.
This gets the value by mutable reference.
Sourcepub fn as_unsigned(&self) -> Result<u64, RuntimeError>
pub fn as_unsigned(&self) -> Result<u64, RuntimeError>
Coerce into u64
unsigned integer.
This gets a copy of the value.
Sourcepub fn as_unsigned_mut(&mut self) -> Result<&mut u64, RuntimeError>
pub fn as_unsigned_mut(&mut self) -> Result<&mut u64, RuntimeError>
Coerce into u64
unsigned integer.
This gets the value by mutable reference.
Sourcepub fn as_signed(&self) -> Result<i64, RuntimeError>
pub fn as_signed(&self) -> Result<i64, RuntimeError>
Coerce into i64
signed integer.
This gets a copy of the value.
Sourcepub fn as_signed_mut(&mut self) -> Result<&mut i64, RuntimeError>
pub fn as_signed_mut(&mut self) -> Result<&mut i64, RuntimeError>
Coerce into i64
signed integer.
This gets the value by mutable reference.
Sourcepub fn as_float(&self) -> Result<f64, RuntimeError>
pub fn as_float(&self) -> Result<f64, RuntimeError>
Coerce into f64
float.
This gets a copy of the value.
Sourcepub fn as_float_mut(&mut self) -> Result<&mut f64, RuntimeError>
pub fn as_float_mut(&mut self) -> Result<&mut f64, RuntimeError>
Coerce into f64
float.
This gets the value by mutable reference.
Sourcepub fn as_type(&self) -> Result<Type, RuntimeError>
pub fn as_type(&self) -> Result<Type, RuntimeError>
Coerce into Type
.
This gets a copy of the value.
Sourcepub fn as_type_mut(&mut self) -> Result<&mut Type, RuntimeError>
pub fn as_type_mut(&mut self) -> Result<&mut Type, RuntimeError>
Coerce into Type
.
This gets the value by mutable reference.
Sourcepub fn into_tuple(self) -> Result<Box<[ConstValue]>, RuntimeError>
pub fn into_tuple(self) -> Result<Box<[ConstValue]>, RuntimeError>
Coerce into tuple.