pub struct ConstValue { /* private fields */ }Expand description
Implementations§
Source§impl ConstValue
impl ConstValue
Sourcepub fn fields(&self) -> ConstFields<'_>
pub fn fields(&self) -> ConstFields<'_>
The subtrees which follow the root, whatever it is.
This is what the code written by the ToConstValue derive reads a
constant’s fields back out of.
Source§impl ConstValue
impl ConstValue
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 as_string(&self) -> Result<&str, ExpectedType>
pub fn as_string(&self) -> Result<&str, ExpectedType>
Coerce into the string this is, if it is one.
Sourcepub fn as_tuple(&self) -> Result<ConstFields<'_>, ExpectedType>
pub fn as_tuple(&self) -> Result<ConstFields<'_>, ExpectedType>
Coerce into the fields of the tuple this is, if it is one.