Struct AnyUserData

Source
pub struct AnyUserData(/* private fields */);
Expand description

Handle to an internal Lua userdata for any type that implements UserData.

Similar to std::any::Any, this provides an interface for dynamic type checking via the is and borrow methods.

§Note

This API should only be used when necessary. Implementing UserData already allows defining methods which check the type and acquire a borrow behind the scenes.

Implementations§

Source§

impl AnyUserData

Source

pub fn is<T>(&self) -> bool
where T: 'static,

Checks whether the type of this userdata is T.

Source

pub fn borrow<T>(&self) -> Result<UserDataRef<T>, Error>
where T: 'static,

Borrow this userdata immutably if it is of type T.

§Errors

Returns a UserDataBorrowError if the userdata is already mutably borrowed. Returns a DataTypeMismatch if the userdata is not of type T or if it’s scoped.

Source

pub fn borrow_scoped<T, R>(&self, f: impl FnOnce(&T) -> R) -> Result<R, Error>
where T: 'static,

Borrow this userdata immutably if it is of type T, passing the borrowed value to the closure.

This method is the only way to borrow scoped userdata (created inside Lua::scope).

Source

pub fn borrow_mut<T>(&self) -> Result<UserDataRefMut<T>, Error>
where T: 'static,

Borrow this userdata mutably if it is of type T.

§Errors

Returns a UserDataBorrowMutError if the userdata cannot be mutably borrowed. Returns a UserDataTypeMismatch if the userdata is not of type T or if it’s scoped.

Source

pub fn borrow_mut_scoped<T, R>( &self, f: impl FnOnce(&mut T) -> R, ) -> Result<R, Error>
where T: 'static,

Borrow this userdata mutably if it is of type T, passing the borrowed value to the closure.

This method is the only way to borrow scoped userdata (created inside Lua::scope).

Source

pub fn take<T>(&self) -> Result<T, Error>
where T: 'static,

Takes the value out of this userdata.

Sets the special “destructed” metatable that prevents any further operations with this userdata.

Keeps associated user values unchanged (they will be collected by Lua’s GC).

Source

pub fn destroy(&self) -> Result<(), Error>

Destroys this userdata.

This is similar to AnyUserData::take, but it doesn’t require a type.

This method works for non-scoped userdata only.

Source

pub fn set_user_value(&self, v: impl IntoLua) -> Result<(), Error>

Sets an associated value to this AnyUserData.

The value may be any Lua value whatsoever, and can be retrieved with user_value.

This is the same as calling set_nth_user_value with n set to 1.

Source

pub fn user_value<V>(&self) -> Result<V, Error>
where V: FromLua,

Returns an associated value set by set_user_value.

This is the same as calling nth_user_value with n set to 1.

Source

pub fn set_nth_user_value(&self, n: usize, v: impl IntoLua) -> Result<(), Error>

Sets an associated nth value to this AnyUserData.

The value may be any Lua value whatsoever, and can be retrieved with nth_user_value. n starts from 1 and can be up to 65535.

This is supported for all Lua versions using a wrapping table.

Source

pub fn nth_user_value<V>(&self, n: usize) -> Result<V, Error>
where V: FromLua,

Returns an associated nth value set by set_nth_user_value.

n starts from 1 and can be up to 65535.

This is supported for all Lua versions using a wrapping table.

Source

pub fn set_named_user_value( &self, name: &str, v: impl IntoLua, ) -> Result<(), Error>

Sets an associated value to this AnyUserData by name.

The value can be retrieved with named_user_value.

Source

pub fn named_user_value<V>(&self, name: &str) -> Result<V, Error>
where V: FromLua,

Returns an associated value by name set by set_named_user_value.

Source

pub fn metatable(&self) -> Result<UserDataMetatable, Error>

Returns a metatable of this AnyUserData.

Returned UserDataMetatable object wraps the original metatable and provides safe access to its methods.

For T: 'static returned metatable is shared among all instances of type T.

Source

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

Converts this userdata to a generic C pointer.

There is no way to convert the pointer back to its original value.

Typically this function is used only for hashing and debug information.

Source§

impl AnyUserData

Source

pub fn wrap<T>(data: T) -> impl IntoLua
where T: MaybeSend + 'static,

Wraps any Rust type, returning an opaque type that implements IntoLua trait.

This function uses Lua::create_any_userdata under the hood.

Trait Implementations§

Source§

impl Clone for AnyUserData

Source§

fn clone(&self) -> AnyUserData

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 AnyUserData

Source§

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

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

impl FromLua for AnyUserData

Source§

fn from_lua(value: Value, _: &Lua) -> Result<AnyUserData, Error>

Performs the conversion.
Source§

impl IntoLua for &AnyUserData

Source§

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

Performs the conversion.
Source§

impl IntoLua for AnyUserData

Source§

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

Performs the conversion.
Source§

impl ObjectLike for AnyUserData

Source§

fn get<V>(&self, key: impl IntoLua) -> Result<V, Error>
where V: FromLua,

Gets the value associated to key from the object, assuming it has __index metamethod.
Source§

fn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<(), Error>

Sets the value associated to key in the object, assuming it has __newindex metamethod.
Source§

fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>
where R: FromLuaMulti,

Calls the object as a function assuming it has __call metamethod. Read more
Source§

fn call_method<R>( &self, name: &str, args: impl IntoLuaMulti, ) -> Result<R, Error>
where R: FromLuaMulti,

Gets the function associated to key name from the object and calls it, passing the object itself along with args as function arguments.
Source§

fn call_function<R>( &self, name: &str, args: impl IntoLuaMulti, ) -> Result<R, Error>
where R: FromLuaMulti,

Gets the function associated to key name from the object and calls it, passing args as function arguments. Read more
Source§

fn to_string(&self) -> Result<String, Error>

Converts the object to a string in a human-readable format. Read more
Source§

impl PartialEq for AnyUserData

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
Source§

impl StructuralPartialEq for AnyUserData

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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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, dst: *mut u8)

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

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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>

Performs the conversion. Read more
Source§

fn from_lua_args( args: MultiValue, i: usize, to: Option<&str>, lua: &Lua, ) -> Result<T, Error>

Source§

unsafe fn from_stack_multi(nvals: i32, lua: &RawLua) -> Result<T, Error>

Source§

unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &RawLua, ) -> Result<T, Error>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoLuaMulti for T
where T: IntoLua,

Source§

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

Performs the conversion.
Source§

unsafe fn push_into_stack_multi(self, lua: &RawLua) -> Result<i32, Error>

Source§

impl<T> IntoNamespace for T
where T: 'static + ?Sized,

Source§

fn into_namespace() -> Namespace

Converts this type into a Namespace
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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> ConditionalSend for T
where T: Send,

Source§

impl<T> Context for T
where T: 'static + Send + Sync,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,