Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 13 variants Nil, Boolean(bool), Integer(Integer), Number(Number), String(LuaString), Table(Table), Function(Function), LightUserData(LightUserData), UserData(AnyUserData), Thread(Thread), Vector(Vector), Buffer(Buffer), Error(Box<Error>),
}
Expand description

A dynamically typed Lua value.

Mirrors mlua::Value. Reference-typed variants (Value::String, Value::Table, Value::Function) carry handles that keep both the value and the VM alive.

Variants§

§

Nil

nil.

§

Boolean(bool)

A boolean.

§

Integer(Integer)

An integer (an f64 that is an exact, in-range whole number).

§

Number(Number)

A floating-point number.

§

String(LuaString)

A string.

§

Table(Table)

A table.

§

Function(Function)

A function (Lua or Rust).

§

LightUserData(LightUserData)

A raw-pointer light userdata. Mirrors mlua::Value::LightUserData.

§

UserData(AnyUserData)

A userdata value with typed Rust-side borrowing.

§

Thread(Thread)

A thread (coroutine).

§

Vector(Vector)

A Luau vector (3 f32 components). Mirrors mlua::Value::Vector.

§

Buffer(Buffer)

A Luau buffer (mutable, fixed-size byte array). Mirrors mlua::Value::Buffer.

§

Error(Box<Error>)

A boxed Lua/Rust error carried as a first-class value (mirrors mlua::Value::Error). Produced when a Rust error is returned to Lua.

Implementations§

Source§

impl Value

Source

pub const NIL: Value = Value::Nil

Value::Nil. Mirrors mlua::Nil.

Source

pub fn type_name(&self) -> &'static str

The Lua type name of this value (e.g. "nil", "number", "table").

Source

pub fn is_error(&self) -> bool

Whether this is an error value.

Source

pub fn as_error(&self) -> Option<&Error>

View as a reference to the contained error, if any.

Source

pub fn is_nil(&self) -> bool

Whether this is nil.

Source

pub fn is_boolean(&self) -> bool

Whether this is a boolean.

Source

pub fn is_number(&self) -> bool

Whether this is a number of either subtype.

Source

pub fn is_integer(&self) -> bool

Whether this is the integer subtype.

Source

pub fn is_string(&self) -> bool

Whether this is a string.

Source

pub fn is_table(&self) -> bool

Whether this is a table.

Source

pub fn is_function(&self) -> bool

Whether this is a function.

Source

pub fn as_boolean(&self) -> Option<bool>

Lua truthiness: everything except nil and false is truthy.

Source

pub fn as_integer(&self) -> Option<Integer>

View as an integer if it is one.

Source

pub fn as_number(&self) -> Option<Number>

View as an f64 if it is a number of either subtype.

Source

pub fn as_string(&self) -> Option<&LuaString>

View as a string handle.

Source

pub fn as_table(&self) -> Option<&Table>

View as a table handle.

Source

pub fn as_function(&self) -> Option<&Function>

View as a function handle.

Source

pub fn is_userdata(&self) -> bool

Whether this is a userdata value.

Source

pub fn as_userdata(&self) -> Option<&AnyUserData>

View as a userdata handle.

Source

pub fn is_thread(&self) -> bool

Whether this is a thread (coroutine) value.

Source

pub fn as_thread(&self) -> Option<&Thread>

View as a thread handle.

Source

pub fn is_vector(&self) -> bool

Whether this is a Luau vector value. Mirrors mlua::Value::is_vector.

Source

pub fn as_vector(&self) -> Option<&Vector>

View as a vector. Mirrors mlua::Value::as_vector.

Source

pub fn is_buffer(&self) -> bool

Whether this is a Luau buffer value. Mirrors mlua::Value::is_buffer.

Source

pub fn as_buffer(&self) -> Option<&Buffer>

View as a buffer handle. Mirrors mlua::Value::as_buffer.

Source

pub fn as_i32(&self) -> Option<i32>

View as an i32 if it is an in-range integer.

Source

pub fn as_u32(&self) -> Option<u32>

View as a u32 if it is an in-range integer.

Source

pub fn as_i64(&self) -> Option<i64>

View as an i64 if it is an integer.

Source

pub fn as_u64(&self) -> Option<u64>

View as a u64 if it is an in-range integer.

Source

pub fn as_isize(&self) -> Option<isize>

View as an isize if it is an in-range integer.

Source

pub fn as_usize(&self) -> Option<usize>

View as a usize if it is an in-range integer.

Source

pub fn as_f32(&self) -> Option<f32>

View as an f32.

Source

pub fn as_f64(&self) -> Option<f64>

View as an f64.

Source

pub fn to_pointer(&self) -> *const c_void

A raw pointer identifying reference-typed values (tables, functions, strings, userdata). Returns null for value-typed (nil/bool/number) values. Mirrors mlua::Value::to_pointer.

Source

pub fn equals(&self, other: &Value) -> Result<bool>

Compare two values for equality honoring __eq metamethods. Mirrors mlua::Value::equals.

Source

pub fn to_string(&self) -> Result<String>

The metatable-aware string form of this value (honors __tostring). Mirrors mlua::Value::to_string.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 FromIterator<Value> for MultiValue

Source§

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

Creates a value from an iterator. Read more
Source§

impl FromLua for Value

Source§

fn from_lua(value: Value, _lua: &Lua) -> Result<Self>

Perform the conversion.
Source§

fn from_lua_arg( arg: Value, _i: usize, _to: Option<&str>, lua: &Lua, ) -> Result<Self>

Convert an argument at 1-based position i. The default forwards to FromLua::from_lua; specific impls can produce nicer messages. Mirrors mlua::FromLua::from_lua_arg.
Source§

impl IntoLua for Value

Source§

fn into_lua(self, _lua: &Lua) -> Result<Value>

Perform the conversion.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

impl !UnwindSafe for Value

§

impl Freeze for Value

§

impl Unpin for Value

§

impl UnsafeUnpin 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> FromLuaMulti for T
where T: FromLua,

Source§

fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>

Perform the conversion.
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> IntoLuaMulti for T
where T: IntoLua,

Source§

fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>

Perform the conversion.
Source§

impl<T> MaybeSend for T

Source§

impl<T> MaybeSync for T

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.