Skip to main content

Value

Struct Value 

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

A script value kept alive in its original Rustia VM.

Unlike OwnedValue, this is a handle rather than a copy. Tables, functions, and userdata keep their identity; strings can contain arbitrary bytes; tables can share values or refer to themselves. Cloning a handle keeps the same value alive and does not copy its contents.

Every operation requires the VM that created the handle. A Rustia::reset_decision invalidates all earlier handles; using one after reset or with another VM returns an error. To keep ordinary data across a reset, copy it with to_owned or deserialize.

Implementations§

Source§

impl Value

Source

pub const fn decision_epoch(&self) -> u64

Returns the decision epoch in which this value was retained.

Source

pub fn kind<C>(&self, rustia: &Rustia<C>) -> Result<ValueType>
where C: HostSchema,

Returns this value’s runtime kind.

Source

pub fn type_name<C>(&self, rustia: &Rustia<C>) -> Result<&'static str>
where C: HostSchema,

Returns this value’s Luau runtime type name.

Source

pub fn is_nil<C>(&self, rustia: &Rustia<C>) -> Result<bool>
where C: HostSchema,

Returns whether this is the nil value.

Source

pub fn truthy<C>(&self, rustia: &Rustia<C>) -> Result<bool>
where C: HostSchema,

Tests Luau truthiness: only nil and false are false. This does not invoke guest code.

Source

pub fn as_boolean<C>(&self, rustia: &Rustia<C>) -> Result<Option<bool>>
where C: HostSchema,

Returns a boolean, or None for another value kind. No coercion is applied.

Source

pub fn as_number<C>(&self, rustia: &Rustia<C>) -> Result<Option<f64>>
where C: HostSchema,

Returns a number, or None for another value kind. No coercion is applied.

Source

pub fn string_bytes<C>(&self, rustia: &mut Rustia<C>) -> Result<Option<Vec<u8>>>
where C: HostSchema,

Copies the exact binary string bytes, or returns None for another kind.

Source

pub fn buffer_bytes<C>(&self, rustia: &mut Rustia<C>) -> Result<Option<Vec<u8>>>
where C: HostSchema,

Copies the current buffer bytes, or returns None for another kind.

Source

pub fn vector_components<C>( &self, rustia: &mut Rustia<C>, ) -> Result<Option<[f32; 3]>>
where C: HostSchema,

Returns the three vector components, or None for another value kind.

Source

pub fn to_owned<C>(&self, rustia: &mut Rustia<C>) -> Result<OwnedValue>
where C: HostSchema,

Copies this value and any nested tables into Rust-owned data.

Non-UTF-8 strings, buffers, vectors, userdata, functions, keys unsupported by crate::OwnedKey, and cyclic graphs return conversion errors. Shared tables are copied independently; table identity is not preserved. Deeply nested tables also return an error once the snapshot depth limit is reached.

Source

pub fn deserialize<T>(&self, rustia: &mut Rustia<impl HostSchema>) -> Result<T>

Deserializes this value without first building an OwnedValue copy.

The returned type must own its data; it cannot borrow strings or other contents from the VM.

ⓘ
use rustia::{Rustia, Value};

fn cannot_borrow(value: &Value, rustia: &mut Rustia) {
    let _: &str = value.deserialize(rustia).unwrap();
}
Source

pub fn as_table<C>(&self, rustia: &Rustia<C>) -> Result<Option<Table>>
where C: HostSchema,

Returns a table handle, or None if this is another value kind.

Source

pub fn as_function<C>(&self, rustia: &Rustia<C>) -> Result<Option<Function>>
where C: HostSchema,

Returns a function handle, or None if this is another value kind.

Source

pub fn raw_equal<C>(&self, rustia: &mut Rustia<C>, other: &Self) -> Result<bool>
where C: HostSchema,

Compares values using raw Luau equality without invoking __eq.

Source§

impl Value

Source

pub fn as_object<T: 'static>( &self, lua: &mut Rustia<impl HostSchema>, ) -> Result<Option<Object<T>>>

Returns a typed Rust-object handle, or None for another payload type.

A stale handle or a handle from another VM returns an error first.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate 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, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Value

§

impl !RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl !UnwindSafe for Value

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

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 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> FromHostArgument for T
where T: Argument,

Source§

impl<T> IntoHostReturn for T
where T: Return,

Source§

impl<T> IntoHostValue for T
where T: Value,