rune::runtime

Struct ConstValue

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

A constant value.

Implementations§

Source§

impl ConstValue

Source

pub fn tuple(values: Box<[ConstValue]>) -> ConstValue

Construct a new tuple constant value.

Source

pub fn for_struct<const N: usize>( hash: Hash, fields: [ConstValue; N], ) -> Result<ConstValue, RuntimeError>

Construct a constant value for a struct.

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 into_tuple(self) -> Result<Box<[ConstValue]>, RuntimeError>

Coerce into tuple.

Trait Implementations§

Source§

impl Debug for ConstValue

Source§

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

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

impl<'de> Deserialize<'de> for ConstValue

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Bytes> for ConstValue

Source§

fn from(value: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<Inline> for ConstValue

Source§

fn from(value: Inline) -> Self

Converts to this type from the input type.
Source§

impl From<Ordering> for ConstValue

Source§

fn from(value: Ordering) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ConstValue

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Type> for ConstValue

Source§

fn from(value: Type) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for ConstValue

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for ConstValue

Source§

fn from(value: char) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for ConstValue

Source§

fn from(value: f32) -> ConstValue

Converts to this type from the input type.
Source§

impl From<f64> for ConstValue

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for ConstValue

Source§

fn from(number: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for ConstValue

Source§

fn from(number: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for ConstValue

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for ConstValue

Source§

fn from(number: i8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for ConstValue

Source§

fn from(number: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for ConstValue

Source§

fn from(number: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for ConstValue

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for ConstValue

Source§

fn from(number: u8) -> Self

Converts to this type from the input type.
Source§

impl FromConstValue for ConstValue

Source§

fn from_const_value(value: ConstValue) -> Result<Self, RuntimeError>

Convert from a constant value.
Source§

impl FromValue for ConstValue

Source§

fn from_value(value: Value) -> Result<Self, RuntimeError>

Try to convert to the given type, from the given value.
Source§

impl Serialize for ConstValue

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToConstValue for ConstValue

Source§

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

Convert into a constant value.
Source§

fn construct() -> Option<Arc<dyn ConstConstruct>>

Return the constant constructor for the given type.
Source§

impl ToValue for ConstValue

Source§

fn to_value(self) -> Result<Value, RuntimeError>

Convert into a value.
Source§

impl TryClone for ConstValue

Source§

fn try_clone(&self) -> Result<Self>

Try to clone the current value, raising an allocation error if it’s unsuccessful.
Source§

fn try_clone_from(&mut self, source: &Self) -> Result<(), Error>

Performs copy-assignment from source. Read more
Source§

impl TryFrom<&[u8]> for ConstValue

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for ConstValue

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i128> for ConstValue

Source§

type Error = RuntimeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: i128) -> Result<Self, RuntimeError>

Performs the conversion.
Source§

impl TryFrom<isize> for ConstValue

Source§

type Error = RuntimeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: isize) -> Result<Self, RuntimeError>

Performs the conversion.
Source§

impl TryFrom<u128> for ConstValue

Source§

type Error = RuntimeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: u128) -> Result<Self, RuntimeError>

Performs the conversion.
Source§

impl TryFrom<usize> for ConstValue

Source§

type Error = RuntimeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: usize) -> Result<Self, RuntimeError>

Performs the conversion.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToReturn for T
where T: ToValue,

Source§

fn to_return(self) -> VmResult<Value>

Convert something into a return value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TryToOwned for T
where T: TryClone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn try_to_owned(&self) -> Result<T, Error>

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

impl<T> UnsafeToValue for T
where T: ToValue,

Source§

type Guard = ()

The type used to guard the unsafe value conversion.
Source§

unsafe fn unsafe_to_value( self, ) -> Result<(Value, <T as UnsafeToValue>::Guard), RuntimeError>

Convert into a value. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T