Skip to main content

ConstValueBuf

Struct ConstValueBuf 

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

A constant value which owns what it is made of.

This is the owned half of the pair, the way ItemBuf is to Item. Everything it is made of is in one allocation, so cloning one is one copy and dropping one is one deallocation, whatever shape the constant is.

Implementations§

Source§

impl ConstValueBuf

Source

pub fn string(value: impl AsRef<str>) -> Result<ConstValueBuf, RuntimeError>

Construct a constant value that is a string.

Source

pub fn bytes(value: impl AsRef<[u8]>) -> Result<ConstValueBuf, RuntimeError>

Construct a constant value that is bytes.

Source

pub fn tuple<I>(fields: I) -> Result<ConstValueBuf, RuntimeError>

Construct a new tuple constant value.

Source

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>§

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

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 Borrow<ConstValue> for ConstValueBuf

Source§

fn borrow(&self) -> &ConstValue

Immutably borrows from an owned value. Read more
Source§

impl Debug for ConstValueBuf

Source§

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

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

impl<'de, M, A> Decode<'de, M, A> for ConstValueBuf
where A: Allocator, ConstNodeKind: Decode<'de, M, A>,

Available on crate feature musli only.
Source§

const IS_BITWISE_DECODE: bool = false

Whether the type is packed. Packed types can be bitwise copied if the representation of the serialization format is identical to the memory layout of the type. Read more
Source§

fn decode<D>(decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M, Allocator = A>,

Decode the current value.
Source§

impl Deref for ConstValueBuf

Source§

type Target = ConstValue

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for ConstValueBuf

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
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.

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<M> Encode<M> for ConstValueBuf
where ConstNodeKind: Encode<M>,

Available on crate feature musli only.
Source§

const IS_BITWISE_ENCODE: bool = false

Whether the type is packed. Packed types can be bitwise copied if the representation of the serialization format is identical to the memory layout of the type. Read more
Source§

type Encode = ConstValueBuf

The underlying type being encoded. Read more
Source§

fn encode<E>(&self, encoder: E) -> Result<(), E::Error>
where E: Encoder<Mode = M>,

Encode the given output.
Source§

fn as_encode(&self) -> &Self::Encode

Coerce into the underlying value being encoded.
Source§

fn size_hint(&self) -> Option<usize>

The number of fields in the type.
Source§

impl From<Hash> for ConstValueBuf

Source§

fn from(value: Hash) -> Self

Converts to this type from the input type.
Source§

impl From<Inline> for ConstValueBuf

Source§

fn from(value: Inline) -> Self

Converts to this type from the input type.
Source§

impl From<Ordering> for ConstValueBuf

Source§

fn from(value: Ordering) -> Self

Converts to this type from the input type.
Source§

impl From<Type> for ConstValueBuf

Source§

fn from(value: Type) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for ConstValueBuf

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for ConstValueBuf

Source§

fn from(value: char) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for ConstValueBuf

Source§

fn from(value: f32) -> ConstValueBuf

Converts to this type from the input type.
Source§

impl From<f64> for ConstValueBuf

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for ConstValueBuf

Source§

fn from(number: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for ConstValueBuf

Source§

fn from(number: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for ConstValueBuf

Source§

fn from(number: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for ConstValueBuf

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for ConstValueBuf

Source§

fn from(number: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for ConstValueBuf

Source§

fn from(number: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for ConstValueBuf

Source§

fn from(number: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for ConstValueBuf

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl FromConstValue for ConstValueBuf

Source§

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

Convert from a constant value.
Source§

impl FromValue for ConstValueBuf

Source§

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

Try to convert to the given type, from the given value.
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.

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 ConstValueBuf

Source§

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

Convert into a constant value.
Source§

impl ToValue for ConstValueBuf

Source§

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

Convert into a value.
Source§

impl TryClone for ConstValueBuf

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 ConstValueBuf

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 ConstValueBuf

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<Box<[u8]>> for ConstValueBuf

Source§

type Error = Error

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

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

Performs the conversion.
Source§

impl TryFrom<Box<str>> for ConstValueBuf

Source§

type Error = Error

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

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

Performs the conversion.
Source§

impl TryFrom<Bytes> for ConstValueBuf

Source§

type Error = Error

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

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

Performs the conversion.
Source§

impl TryFrom<String> for ConstValueBuf

Source§

type Error = Error

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

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

Performs the conversion.
Source§

impl TryFrom<i128> for ConstValueBuf

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 ConstValueBuf

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 ConstValueBuf

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 ConstValueBuf

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<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<M, D, A> DecodeOwned<M, A> for D
where D: for<'de> Decode<'de, M, A>, A: Allocator,

Source§

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

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> IntoReturn for T
where T: ToValue,

Source§

fn into_return(self) -> Result<Value, VmError>

Convert something into a return value.
Source§

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<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