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
impl Value
Sourcepub const fn decision_epoch(&self) -> u64
pub const fn decision_epoch(&self) -> u64
Returns the decision epoch in which this value was retained.
Sourcepub fn kind<C>(&self, rustia: &Rustia<C>) -> Result<ValueType>where
C: HostSchema,
pub fn kind<C>(&self, rustia: &Rustia<C>) -> Result<ValueType>where
C: HostSchema,
Returns this value’s runtime kind.
Sourcepub fn type_name<C>(&self, rustia: &Rustia<C>) -> Result<&'static str>where
C: HostSchema,
pub fn type_name<C>(&self, rustia: &Rustia<C>) -> Result<&'static str>where
C: HostSchema,
Returns this value’s Luau runtime type name.
Sourcepub fn is_nil<C>(&self, rustia: &Rustia<C>) -> Result<bool>where
C: HostSchema,
pub fn is_nil<C>(&self, rustia: &Rustia<C>) -> Result<bool>where
C: HostSchema,
Returns whether this is the nil value.
Sourcepub fn truthy<C>(&self, rustia: &Rustia<C>) -> Result<bool>where
C: HostSchema,
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.
Sourcepub fn as_boolean<C>(&self, rustia: &Rustia<C>) -> Result<Option<bool>>where
C: HostSchema,
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.
Sourcepub fn as_number<C>(&self, rustia: &Rustia<C>) -> Result<Option<f64>>where
C: HostSchema,
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.
Sourcepub fn string_bytes<C>(&self, rustia: &mut Rustia<C>) -> Result<Option<Vec<u8>>>where
C: HostSchema,
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.
Sourcepub fn buffer_bytes<C>(&self, rustia: &mut Rustia<C>) -> Result<Option<Vec<u8>>>where
C: HostSchema,
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.
Sourcepub fn vector_components<C>(
&self,
rustia: &mut Rustia<C>,
) -> Result<Option<[f32; 3]>>where
C: HostSchema,
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.
Sourcepub fn to_owned<C>(&self, rustia: &mut Rustia<C>) -> Result<OwnedValue>where
C: HostSchema,
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.
Sourcepub fn deserialize<T>(&self, rustia: &mut Rustia<impl HostSchema>) -> Result<T>where
T: DeserializeOwned,
pub fn deserialize<T>(&self, rustia: &mut Rustia<impl HostSchema>) -> Result<T>where
T: DeserializeOwned,
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();
}Sourcepub fn as_table<C>(&self, rustia: &Rustia<C>) -> Result<Option<Table>>where
C: HostSchema,
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.
Sourcepub fn as_function<C>(&self, rustia: &Rustia<C>) -> Result<Option<Function>>where
C: HostSchema,
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.