Skip to main content

ConstValue

Struct ConstValue 

Source
pub struct ConstValue { /* private fields */ }
Expand description

A constant value.

This is the borrowed half of the pair, the way Item is to ItemBuf - a subtree of a constant is a run of the array its parent is stored in, so a field of a constant is one of these rather than something which had to be copied out.

Implementations§

Source§

impl ConstValue

Source

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

Source

pub fn as_integer<T>(&self) -> Result<T, RuntimeError>
where T: TryFrom<i64> + TryFrom<u64>,

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());
Source

pub fn as_ordering(&self) -> Result<Ordering, RuntimeError>

Coerce into Ordering.

This gets a copy of the value.

Source

pub fn as_ordering_mut(&mut self) -> Result<&mut Ordering, RuntimeError>

Coerce into Ordering.

This gets the value by mutable reference.

Source

pub fn as_bool(&self) -> Result<bool, RuntimeError>

Coerce into bool.

This gets a copy of the value.

Source

pub fn as_bool_mut(&mut self) -> Result<&mut bool, RuntimeError>

Coerce into bool.

This gets the value by mutable reference.

Source

pub fn as_char(&self) -> Result<char, RuntimeError>

Coerce into char.

This gets a copy of the value.

Source

pub fn as_char_mut(&mut self) -> Result<&mut char, RuntimeError>

Coerce into char.

This gets the value by mutable reference.

Source

pub fn as_unsigned(&self) -> Result<u64, RuntimeError>

Coerce into u64 unsigned integer.

This gets a copy of the value.

Source

pub fn as_unsigned_mut(&mut self) -> Result<&mut u64, RuntimeError>

Coerce into u64 unsigned integer.

This gets the value by mutable reference.

Source

pub fn as_signed(&self) -> Result<i64, RuntimeError>

Coerce into i64 signed integer.

This gets a copy of the value.

Source

pub fn as_signed_mut(&mut self) -> Result<&mut i64, RuntimeError>

Coerce into i64 signed integer.

This gets the value by mutable reference.

Source

pub fn as_float(&self) -> Result<f64, RuntimeError>

Coerce into f64 float.

This gets a copy of the value.

Source

pub fn as_float_mut(&mut self) -> Result<&mut f64, RuntimeError>

Coerce into f64 float.

This gets the value by mutable reference.

Source

pub fn as_type(&self) -> Result<Type, RuntimeError>

Coerce into Type.

This gets a copy of the value.

Source

pub fn as_type_mut(&mut self) -> Result<&mut Type, RuntimeError>

Coerce into Type.

This gets the value by mutable reference.

Source

pub fn as_string(&self) -> Result<&str, ExpectedType>

Coerce into the string this is, if it is one.

Source

pub fn as_tuple(&self) -> Result<ConstFields<'_>, ExpectedType>

Coerce into the fields of the tuple this is, if it is one.

Trait Implementations§

Source§

impl AsRef<ConstValue> for ConstValueBuf

Source§

fn as_ref(&self) -> &ConstValue

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<ConstValue> for ConstValue

Source§

fn as_ref(&self) -> &ConstValue

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<ConstValue> for ConstValueBuf

Source§

fn borrow(&self) -> &ConstValue

Immutably borrows from an owned value. Read more
Source§

impl Debug for ConstValue

Source§

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

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

impl ToConstValue for &ConstValue

Source§

fn to_const_value(self) -> Result<ConstValueBuf, RuntimeError>

Convert into a constant value.
Source§

impl TryToOwned for ConstValue

Source§

type Owned = ConstValueBuf

The resulting type after obtaining ownership.
Source§

fn try_to_owned(&self) -> Result<Self::Owned>

Creates owned data from borrowed data, usually by cloning. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,