pub struct ConstValue { /* private fields */ }Expand description
A constant value.
Implementations§
Source§impl ConstValue
impl ConstValue
Sourcepub fn string(value: impl AsRef<str>) -> Result<ConstValue, RuntimeError>
pub fn string(value: impl AsRef<str>) -> Result<ConstValue, RuntimeError>
Construct a constant value that is a string.
Sourcepub fn bytes(value: impl AsRef<[u8]>) -> Result<ConstValue, RuntimeError>
pub fn bytes(value: impl AsRef<[u8]>) -> Result<ConstValue, RuntimeError>
Construct a constant value that is bytes.
Sourcepub fn tuple(fields: Box<[ConstValue]>) -> Result<ConstValue, RuntimeError>
pub fn tuple(fields: Box<[ConstValue]>) -> Result<ConstValue, RuntimeError>
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]>, ExpectedType>
pub fn into_tuple(self) -> Result<Box<[ConstValue]>, ExpectedType>
Coerce into tuple.
Trait Implementations§
Source§impl Debug for ConstValue
impl Debug for ConstValue
Source§impl<'__de, __A> Decode<'__de, Binary, __A> for ConstValuewhere
__A: Allocator,
Available on crate feature musli only.
impl<'__de, __A> Decode<'__de, Binary, __A> for ConstValuewhere
__A: Allocator,
musli only.Source§const IS_BITWISE_DECODE: bool = false
const IS_BITWISE_DECODE: bool = false
Source§impl<'__de, __A> Decode<'__de, Text, __A> for ConstValuewhere
__A: Allocator,
Available on crate feature musli only.
impl<'__de, __A> Decode<'__de, Text, __A> for ConstValuewhere
__A: Allocator,
musli only.Source§const IS_BITWISE_DECODE: bool = false
const IS_BITWISE_DECODE: bool = false
Source§impl<'de> Deserialize<'de> for ConstValue
Available on crate feature serde only.
impl<'de> Deserialize<'de> for ConstValue
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Encode<Binary> for ConstValue
Available on crate feature musli only.
impl Encode<Binary> for ConstValue
musli only.Source§const IS_BITWISE_ENCODE: bool = false
const IS_BITWISE_ENCODE: bool = false
Source§type Encode = ConstValue
type Encode = ConstValue
Source§impl Encode<Text> for ConstValue
Available on crate feature musli only.
impl Encode<Text> for ConstValue
musli only.Source§const IS_BITWISE_ENCODE: bool = false
const IS_BITWISE_ENCODE: bool = false
Source§type Encode = ConstValue
type Encode = ConstValue
Source§impl From<Hash> for ConstValue
impl From<Hash> for ConstValue
Source§impl From<Inline> for ConstValue
impl From<Inline> for ConstValue
Source§impl From<Ordering> for ConstValue
impl From<Ordering> for ConstValue
Source§impl From<Type> for ConstValue
impl From<Type> for ConstValue
Source§impl From<bool> for ConstValue
impl From<bool> for ConstValue
Source§impl From<char> for ConstValue
impl From<char> for ConstValue
Source§impl From<f32> for ConstValue
impl From<f32> for ConstValue
Source§fn from(value: f32) -> ConstValue
fn from(value: f32) -> ConstValue
Source§impl From<f64> for ConstValue
impl From<f64> for ConstValue
Source§impl From<i8> for ConstValue
impl From<i8> for ConstValue
Source§impl From<i16> for ConstValue
impl From<i16> for ConstValue
Source§impl From<i32> for ConstValue
impl From<i32> for ConstValue
Source§impl From<i64> for ConstValue
impl From<i64> for ConstValue
Source§impl From<u8> for ConstValue
impl From<u8> for ConstValue
Source§impl From<u16> for ConstValue
impl From<u16> for ConstValue
Source§impl From<u32> for ConstValue
impl From<u32> for ConstValue
Source§impl From<u64> for ConstValue
impl From<u64> for ConstValue
Source§impl FromConstValue for ConstValue
impl FromConstValue for ConstValue
Source§fn from_const_value(value: ConstValue) -> Result<Self, RuntimeError>
fn from_const_value(value: ConstValue) -> Result<Self, RuntimeError>
Source§impl FromValue for ConstValue
impl FromValue for ConstValue
Source§fn from_value(value: Value) -> Result<Self, RuntimeError>
fn from_value(value: Value) -> Result<Self, RuntimeError>
Source§impl Serialize for ConstValue
Available on crate feature serde only.
impl Serialize for ConstValue
serde only.