Enum rune::runtime::Value

source ·
pub enum Value {
Show 28 variants Unit, Bool(bool), Byte(u8), Char(char), Integer(i64), Float(f64), Type(Hash), StaticString(Arc<StaticString>), String(Shared<String>), Bytes(Shared<Bytes>), Vec(Shared<Vec>), Tuple(Shared<Tuple>), Object(Shared<Object>), Range(Shared<Range>), Future(Shared<Future>), Stream(Shared<Stream<Vm>>), Generator(Shared<Generator<Vm>>), GeneratorState(Shared<GeneratorState>), Option(Shared<Option<Value>>), Result(Shared<Result<Value, Value>>), UnitStruct(Shared<UnitStruct>), TupleStruct(Shared<TupleStruct>), Struct(Shared<Struct>), Variant(Shared<Variant>), Function(Shared<Function>), Format(Box<Format>), Iterator(Shared<Iterator>), Any(Shared<AnyObj>),
}
Expand description

An entry on the stack.

Variants§

§

Unit

The unit value.

§

Bool(bool)

A boolean.

§

Byte(u8)

A single byte.

§

Char(char)

A character.

§

Integer(i64)

A number.

§

Float(f64)

A float.

§

Type(Hash)

A type hash. Describes a type in the virtual machine.

§

StaticString(Arc<StaticString>)

A static string.

While Rc<str> would’ve been enough to store an unsized str, either Box<str> or String must be used to reduce the size of the type to 8 bytes, to ensure that a stack value is 16 bytes in size.

Rc<str> on the other hand wraps a so-called fat pointer, which is 16 bytes.

§

String(Shared<String>)

A UTF-8 string.

§

Bytes(Shared<Bytes>)

A byte string.

§

Vec(Shared<Vec>)

A vector containing any values.

§

Tuple(Shared<Tuple>)

A tuple.

§

Object(Shared<Object>)

An object.

§

Range(Shared<Range>)

A range.

§

Future(Shared<Future>)

A stored future.

§

Stream(Shared<Stream<Vm>>)

A Stream.

§

Generator(Shared<Generator<Vm>>)

A stored generator.

§

GeneratorState(Shared<GeneratorState>)

Generator state.

§

Option(Shared<Option<Value>>)

An empty value indicating nothing.

§

Result(Shared<Result<Value, Value>>)

A stored result in a slot.

§

UnitStruct(Shared<UnitStruct>)

An struct with a well-defined type.

§

TupleStruct(Shared<TupleStruct>)

A tuple with a well-defined type.

§

Struct(Shared<Struct>)

An struct with a well-defined type.

§

Variant(Shared<Variant>)

The variant of an enum.

§

Function(Shared<Function>)

A stored function pointer.

§

Format(Box<Format>)

A value being formatted.

§

Iterator(Shared<Iterator>)

An iterator.

§

Any(Shared<AnyObj>)

An opaque value that can be downcasted.

Implementations§

source§

impl Value

source

pub fn string_display( &self, s: &mut String, buf: &mut String ) -> Result<Result, VmError>

Format the value using the Protocol::STRING_DISPLAY protocol.

Requires a work buffer buf which will be used in case the value provided requires out-of-line formatting. This must be cleared between calls and can be re-used.

You must use Vm::with to specify which virtual machine this function is called inside.

Panics

This function will panic if called outside of a virtual machine.

source

pub fn string_debug(&self, s: &mut String) -> Result<Result, VmError>

Debug format the value using the Protocol::STRING_DEBUG protocol.

You must use Vm::with to specify which virtual machine this function is called inside.

Panics

This function will panic if called outside of a virtual machine.

source

pub fn into_iter(self) -> Result<Iterator, VmError>

Convert value into an iterator using the Protocol::INTO_ITER protocol.

You must use Vm::with to specify which virtual machine this function is called inside.

Panics

This function will panic if called outside of a virtual machine.

source

pub fn into_future(self) -> Result<Future, VmError>

Coerce into future, or convert into a future using the Protocol::INTO_FUTURE protocol.

You must use Vm::with to specify which virtual machine this function is called inside.

Panics

This function will panic if called outside of a virtual machine.

source

pub fn into_shared_future(self) -> Result<Shared<Future>, VmError>

Coerce into a shared future, or convert into a future using the Protocol::INTO_FUTURE protocol.

You must use Vm::with to specify which virtual machine this function is called inside.

Panics

This function will panic if called outside of a virtual machine.

source

pub fn into_type_name(self) -> Result<String, VmError>

Retrieves a human readable type name for the current value.

You must use Vm::with to specify which virtual machine this function is called inside.

Panics

This function will panic if called outside of a virtual machine.

source

pub fn vec(vec: Vec<Value>) -> Self

Construct a vector.

source

pub fn tuple(vec: Vec<Value>) -> Self

Construct a tuple.

source

pub fn unit_struct(rtti: Arc<Rtti>) -> Self

Construct an empty.

source

pub fn tuple_struct(rtti: Arc<Rtti>, vec: Vec<Value>) -> Self

Construct a typed tuple.

source

pub fn unit_variant(rtti: Arc<VariantRtti>) -> Self

Construct an empty variant.

source

pub fn tuple_variant(rtti: Arc<VariantRtti>, vec: Vec<Value>) -> Self

Construct a tuple variant.

source

pub fn take(self) -> Result<Self, VmError>

Take the interior value.

source

pub fn into_unit(self) -> Result<(), VmError>

Try to coerce value into a unit.

source

pub fn into_bool(self) -> Result<bool, VmError>

Try to coerce value into a boolean.

source

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

Try to coerce value into a boolean.

source

pub fn into_byte(self) -> Result<u8, VmError>

Try to coerce value into a byte.

source

pub fn into_char(self) -> Result<char, VmError>

Try to coerce value into a character.

source

pub fn into_integer(self) -> Result<i64, VmError>

Try to coerce value into an integer.

source

pub fn into_float(self) -> Result<f64, VmError>

Try to coerce value into a float.

source

pub fn into_result(self) -> Result<Shared<Result<Value, Value>>, VmError>

Try to coerce value into a result.

source

pub fn into_generator(self) -> Result<Shared<Generator<Vm>>, VmError>

Try to coerce value into a generator.

source

pub fn into_stream(self) -> Result<Shared<Stream<Vm>>, VmError>

Try to coerce value into a stream.

source

pub fn into_generator_state(self) -> Result<Shared<GeneratorState>, VmError>

Try to coerce value into a future.

source

pub fn into_option(self) -> Result<Shared<Option<Value>>, VmError>

Try to coerce value into an option.

source

pub fn into_string(self) -> Result<Shared<String>, VmError>

Try to coerce value into a string.

source

pub fn into_bytes(self) -> Result<Shared<Bytes>, VmError>

Try to coerce value into bytes.

source

pub fn into_vec(self) -> Result<Shared<Vec>, VmError>

Try to coerce value into a vector.

source

pub fn into_tuple(self) -> Result<Shared<Tuple>, VmError>

Try to coerce value into a tuple.

source

pub fn into_object(self) -> Result<Shared<Object>, VmError>

Try to coerce value into an object.

source

pub fn into_range(self) -> Result<Shared<Range>, VmError>

Try to coerce value into a range.

source

pub fn into_function(self) -> Result<Shared<Function>, VmError>

Try to coerce value into a function pointer.

source

pub fn into_format(self) -> Result<Box<Format>, VmError>

Try to coerce value into a format spec.

source

pub fn into_iterator(self) -> Result<Shared<Iterator>, VmError>

Try to coerce value into an iterator.

source

pub fn into_any(self) -> Result<Shared<AnyObj>, VmError>

Try to coerce value into an opaque value.

source

pub fn into_any_ptr<T>(self) -> Result<(*const T, RawRef), VmError>where T: Any,

Try to coerce value into a ref and an associated guard.

Safety

This coerces a strong guard to the value into its raw components.

It is up to the caller to ensure that the returned pointer does not outlive the returned guard, not the virtual machine the value belongs to.

source

pub fn into_any_mut<T>(self) -> Result<(*mut T, RawMut), VmError>where T: Any,

Try to coerce value into a ref and an associated guard.

Safety

This coerces a strong guard to the value into its raw components.

It is up to the caller to ensure that the returned pointer does not outlive the returned guard, not the virtual machine the value belongs to.

source

pub fn type_hash(&self) -> Result<Hash, VmError>

Get the type hash for the current value.

One notable feature is that the type of a variant is its container enum, and not the type hash of the variant itself.

source

pub fn type_info(&self) -> Result<TypeInfo, VmError>

Get the type information for the current value.

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Value

source§

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

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

impl Default for Value

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Value

Deserialize implementation for value pointers.

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<()> for Value

source§

fn from((): ()) -> Self

Converts to this type from the input type.
source§

impl From<AnyObj> for Value

source§

fn from(value: AnyObj) -> Self

Converts to this type from the input type.
source§

impl From<Arc<StaticString>> for Value

source§

fn from(value: Arc<StaticString>) -> Self

Converts to this type from the input type.
source§

impl From<Box<Format, Global>> for Value

source§

fn from(value: Box<Format>) -> Self

Converts to this type from the input type.
source§

impl From<Bytes> for Value

source§

fn from(value: Bytes) -> Self

Converts to this type from the input type.
source§

impl From<Format> for Value

source§

fn from(value: Format) -> Self

Converts to this type from the input type.
source§

impl From<Function> for Value

source§

fn from(value: Function) -> Self

Converts to this type from the input type.
source§

impl From<Future> for Value

source§

fn from(value: Future) -> Self

Converts to this type from the input type.
source§

impl From<Generator<Vm>> for Value

source§

fn from(value: Generator<Vm>) -> Self

Converts to this type from the input type.
source§

impl From<GeneratorState> for Value

source§

fn from(value: GeneratorState) -> Self

Converts to this type from the input type.
source§

impl From<Iterator> for Value

source§

fn from(value: Iterator) -> Self

Converts to this type from the input type.
source§

impl From<Object> for Value

source§

fn from(value: Object) -> Self

Converts to this type from the input type.
source§

impl From<Range> for Value

source§

fn from(value: Range) -> Self

Converts to this type from the input type.
source§

impl From<Shared<AnyObj>> for Value

source§

fn from(value: Shared<AnyObj>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Bytes>> for Value

source§

fn from(value: Shared<Bytes>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Function>> for Value

source§

fn from(value: Shared<Function>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Future>> for Value

source§

fn from(value: Shared<Future>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Generator<Vm>>> for Value

source§

fn from(value: Shared<Generator<Vm>>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<GeneratorState>> for Value

source§

fn from(value: Shared<GeneratorState>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Iterator>> for Value

source§

fn from(value: Shared<Iterator>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Object>> for Value

source§

fn from(value: Shared<Object>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Option<Value>>> for Value

source§

fn from(value: Shared<Option<Value>>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Range>> for Value

source§

fn from(value: Shared<Range>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Result<Value, Value>>> for Value

source§

fn from(value: Shared<Result<Value, Value>>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Stream<Vm>>> for Value

source§

fn from(value: Shared<Stream<Vm>>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<String>> for Value

source§

fn from(value: Shared<String>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Struct>> for Value

source§

fn from(value: Shared<Struct>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Tuple>> for Value

source§

fn from(value: Shared<Tuple>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<TupleStruct>> for Value

source§

fn from(value: Shared<TupleStruct>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<UnitStruct>> for Value

source§

fn from(value: Shared<UnitStruct>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Variant>> for Value

source§

fn from(value: Shared<Variant>) -> Self

Converts to this type from the input type.
source§

impl From<Shared<Vec>> for Value

source§

fn from(value: Shared<Vec>) -> Self

Converts to this type from the input type.
source§

impl From<StaticString> for Value

source§

fn from(value: StaticString) -> Self

Converts to this type from the input type.
source§

impl From<Stream<Vm>> for Value

source§

fn from(value: Stream<Vm>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Value

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl From<Struct> for Value

source§

fn from(value: Struct) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Valuewhere T: Any,

source§

fn from(any: T) -> Self

Converts to this type from the input type.
source§

impl From<Tuple> for Value

source§

fn from(value: Tuple) -> Self

Converts to this type from the input type.
source§

impl From<TupleStruct> for Value

source§

fn from(value: TupleStruct) -> Self

Converts to this type from the input type.
source§

impl From<UnitStruct> for Value

source§

fn from(value: UnitStruct) -> Self

Converts to this type from the input type.
source§

impl From<Variant> for Value

source§

fn from(value: Variant) -> Self

Converts to this type from the input type.
source§

impl From<Vec> for Value

source§

fn from(value: Vec) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Value

source§

fn from(value: bool) -> Self

Converts to this type from the input type.
source§

impl From<char> for Value

source§

fn from(value: char) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

source§

fn from(value: f64) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Value

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Value

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl FromIterator<Value> for Stack

source§

fn from_iter<T: IntoIterator<Item = Value>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromValue for Value

source§

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

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

impl Serialize for Value

Serialize implementation for value pointers.

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 ToValue for &Value

source§

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

Convert into a value.
source§

impl ToValue for Value

source§

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

Convert into a value.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

impl Unpin for Value

§

impl !UnwindSafe for Value

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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> UnsafeFromValue for Twhere T: FromValue,

§

type Output = T

The output type from the unsafe coercion.
§

type Guard = ()

The raw guard returned. Read more
source§

fn from_value( value: Value ) -> Result<(T, <T as UnsafeFromValue>::Guard), VmError>

Convert the given reference using unsafe assumptions to a value. Read more
source§

unsafe fn unsafe_coerce(output: <T as UnsafeFromValue>::Output) -> T

Coerce the output of an unsafe from value into the final output type. Read more
source§

impl<T> UnsafeToValue for Twhere T: ToValue,

§

type Guard = ()

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

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

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

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