pub struct ConstValueBuf { /* private fields */ }Expand description
Implementations§
Source§impl ConstValueBuf
impl ConstValueBuf
Sourcepub fn string(value: impl AsRef<str>) -> Result<ConstValueBuf, RuntimeError>
pub fn string(value: impl AsRef<str>) -> Result<ConstValueBuf, RuntimeError>
Construct a constant value that is a string.
Sourcepub fn bytes(value: impl AsRef<[u8]>) -> Result<ConstValueBuf, RuntimeError>
pub fn bytes(value: impl AsRef<[u8]>) -> Result<ConstValueBuf, RuntimeError>
Construct a constant value that is bytes.
Sourcepub fn tuple<I>(fields: I) -> Result<ConstValueBuf, RuntimeError>
pub fn tuple<I>(fields: I) -> Result<ConstValueBuf, RuntimeError>
Construct a new tuple constant value.
Sourcepub fn for_struct<const N: usize>(
hash: Hash,
fields: [ConstValueBuf; N],
) -> Result<ConstValueBuf, RuntimeError>
pub fn for_struct<const N: usize>( hash: Hash, fields: [ConstValueBuf; N], ) -> Result<ConstValueBuf, RuntimeError>
Construct a constant value for a struct.
Methods from Deref<Target = 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.
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.
Trait Implementations§
Source§impl AsRef<ConstValue> for ConstValueBuf
impl AsRef<ConstValue> for ConstValueBuf
Source§fn as_ref(&self) -> &ConstValue
fn as_ref(&self) -> &ConstValue
Source§impl Borrow<ConstValue> for ConstValueBuf
impl Borrow<ConstValue> for ConstValueBuf
Source§fn borrow(&self) -> &ConstValue
fn borrow(&self) -> &ConstValue
Source§impl Debug for ConstValueBuf
impl Debug for ConstValueBuf
Source§impl<'de, M, A> Decode<'de, M, A> for ConstValueBuf
Available on crate feature musli only.
impl<'de, M, A> Decode<'de, M, A> for ConstValueBuf
musli only.Source§const IS_BITWISE_DECODE: bool = false
const IS_BITWISE_DECODE: bool = false
Source§impl Deref for ConstValueBuf
impl Deref for ConstValueBuf
Source§impl DerefMut for ConstValueBuf
impl DerefMut for ConstValueBuf
Source§impl<'de> Deserialize<'de> for ConstValueBuf
Available on crate feature serde only.Reading a constant back checks that what was written down is a tree, and
that it is one within the limits, before anything walks it.
impl<'de> Deserialize<'de> for ConstValueBuf
serde only.Reading a constant back checks that what was written down is a tree, and that it is one within the limits, before anything walks it.
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<M> Encode<M> for ConstValueBufwhere
ConstNodeKind: Encode<M>,
Available on crate feature musli only.
impl<M> Encode<M> for ConstValueBufwhere
ConstNodeKind: Encode<M>,
musli only.Source§const IS_BITWISE_ENCODE: bool = false
const IS_BITWISE_ENCODE: bool = false
Source§type Encode = ConstValueBuf
type Encode = ConstValueBuf
Source§impl From<Hash> for ConstValueBuf
impl From<Hash> for ConstValueBuf
Source§impl From<Inline> for ConstValueBuf
impl From<Inline> for ConstValueBuf
Source§impl From<Ordering> for ConstValueBuf
impl From<Ordering> for ConstValueBuf
Source§impl From<Type> for ConstValueBuf
impl From<Type> for ConstValueBuf
Source§impl From<bool> for ConstValueBuf
impl From<bool> for ConstValueBuf
Source§impl From<char> for ConstValueBuf
impl From<char> for ConstValueBuf
Source§impl From<f32> for ConstValueBuf
impl From<f32> for ConstValueBuf
Source§fn from(value: f32) -> ConstValueBuf
fn from(value: f32) -> ConstValueBuf
Source§impl From<f64> for ConstValueBuf
impl From<f64> for ConstValueBuf
Source§impl From<i8> for ConstValueBuf
impl From<i8> for ConstValueBuf
Source§impl From<i16> for ConstValueBuf
impl From<i16> for ConstValueBuf
Source§impl From<i32> for ConstValueBuf
impl From<i32> for ConstValueBuf
Source§impl From<i64> for ConstValueBuf
impl From<i64> for ConstValueBuf
Source§impl From<u8> for ConstValueBuf
impl From<u8> for ConstValueBuf
Source§impl From<u16> for ConstValueBuf
impl From<u16> for ConstValueBuf
Source§impl From<u32> for ConstValueBuf
impl From<u32> for ConstValueBuf
Source§impl From<u64> for ConstValueBuf
impl From<u64> for ConstValueBuf
Source§impl FromConstValue for ConstValueBuf
impl FromConstValue for ConstValueBuf
Source§fn from_const_value(value: &ConstValue) -> Result<Self, RuntimeError>
fn from_const_value(value: &ConstValue) -> Result<Self, RuntimeError>
Source§impl FromValue for ConstValueBuf
impl FromValue for ConstValueBuf
Source§fn from_value(value: Value) -> Result<Self, RuntimeError>
fn from_value(value: Value) -> Result<Self, RuntimeError>
Source§impl Serialize for ConstValueBuf
Available on crate feature serde only.A constant is written down as the kinds its nodes are, since the shape is
worked out from them again when it is read back - so there is nothing for a
size written down to disagree with.
impl Serialize for ConstValueBuf
serde only.A constant is written down as the kinds its nodes are, since the shape is worked out from them again when it is read back - so there is nothing for a size written down to disagree with.