Struct actix_lua::dev::rlua::AnyUserData
source · 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
sourceimpl<'lua> AnyUserData<'lua>
impl<'lua> AnyUserData<'lua>
sourcepub fn is<T>(&self) -> boolwhere
T: 'static + UserData,
pub fn is<T>(&self) -> boolwhere
T: 'static + UserData,
Checks whether the type of this userdata is T
.
sourcepub fn borrow<T>(&self) -> Result<Ref<'_, T>, Error>where
T: 'static + UserData,
pub fn borrow<T>(&self) -> Result<Ref<'_, T>, Error>where
T: 'static + UserData,
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
.
sourcepub fn borrow_mut<T>(&self) -> Result<RefMut<'_, T>, Error>where
T: 'static + UserData,
pub fn borrow_mut<T>(&self) -> Result<RefMut<'_, T>, Error>where
T: 'static + UserData,
Borrow this userdata mutably if it is of type T
.
Errors
Returns a UserDataBorrowMutError
if the userdata is already borrowed. Returns a
UserDataTypeMismatch
if the userdata is not of type T
.
sourcepub fn set_user_value<V>(&self, v: V) -> Result<(), Error>where
V: ToLua<'lua>,
pub fn set_user_value<V>(&self, v: V) -> Result<(), Error>where
V: ToLua<'lua>,
Sets an associated value to this AnyUserData
.
The value may be any Lua value whatsoever, and can be retrieved with get_user_value
.
sourcepub fn get_user_value<V>(&self) -> Result<V, Error>where
V: FromLua<'lua>,
pub fn get_user_value<V>(&self) -> Result<V, Error>where
V: FromLua<'lua>,
Returns an associated value set by set_user_value
.
Trait Implementations
sourceimpl<'lua> Clone for AnyUserData<'lua>
impl<'lua> Clone for AnyUserData<'lua>
sourcefn clone(&self) -> AnyUserData<'lua>
fn clone(&self) -> AnyUserData<'lua>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more