pub struct AnyUserData<'lua>(_);
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.

Internally, instances are stored in a RefCell, to best match the mutable semantics of the Lua language.

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

Checks whether the type of this userdata is T.

Borrow this userdata immutably if it is of type T.

Errors

Returns a UserDataBorrowError if the userdata is already mutably borrowed. Returns a UserDataTypeMismatch if the userdata is not of type T.

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.

Takes out the value of UserData and sets the special “destructed” metatable that prevents any further operations with this userdata.

All associated user values will be also cleared.

Sets an associated value to this AnyUserData.

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

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

Returns an associated value set by set_user_value.

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

Sets an associated nth value to this AnyUserData.

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

This is supported for all Lua versions. In Lua 5.4 first 7 elements are stored in a most efficient way. For other Lua versions this functionality is provided using a wrapping table.

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. In Lua 5.4 first 7 elements are stored in a most efficient way. For other Lua versions this functionality is provided using a wrapping table.

Sets an associated value to this AnyUserData by name.

The value can be retrieved with get_named_user_value.

Returns an associated value by name set by set_named_user_value.

Returns a metatable of this UserData.

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

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

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.