Struct 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 borrow<T: 'static + UserData>(&self) -> Result<Ref<'_, T>>
pub fn borrow<T: 'static + UserData>(&self) -> Result<Ref<'_, 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
.
sourcepub fn borrow_mut<T: 'static + UserData>(&self) -> Result<RefMut<'_, T>>
pub fn borrow_mut<T: 'static + UserData>(&self) -> Result<RefMut<'_, T>>
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: ToLua<'lua>>(&self, v: V) -> Result<()>
pub fn set_user_value<V: ToLua<'lua>>(&self, v: V) -> Result<()>
Sets an associated value to this AnyUserData
.
The value may be any Lua value whatsoever, and can be retrieved with AnyUserData::get_user_value
.
Equivalent to set_i_user_value(v, 1)
sourcepub fn set_i_user_value<V: ToLua<'lua>>(&self, v: V, n: c_int) -> Result<()>
pub fn set_i_user_value<V: ToLua<'lua>>(&self, v: V, n: c_int) -> Result<()>
Sets an associated value to this AnyUserData
.
The value may be any Lua value whatsoever, and can be retrieved with get_i_user_value
.
sourcepub fn get_user_value<V: FromLua<'lua>>(&self) -> Result<V>
pub fn get_user_value<V: FromLua<'lua>>(&self) -> Result<V>
Returns an associated value set by set_user_value
.
sourcepub fn get_i_user_value<V: FromLua<'lua>>(&self, n: c_int) -> Result<V>
pub fn get_i_user_value<V: FromLua<'lua>>(&self, n: c_int) -> Result<V>
Returns an associated value set by set_i_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>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'lua> Debug for AnyUserData<'lua>
impl<'lua> Debug for AnyUserData<'lua>
sourceimpl<'lua> FromLua<'lua> for AnyUserData<'lua>
impl<'lua> FromLua<'lua> for AnyUserData<'lua>
Auto Trait Implementations
impl<'lua> !RefUnwindSafe for AnyUserData<'lua>
impl<'lua> !Send for AnyUserData<'lua>
impl<'lua> !Sync for AnyUserData<'lua>
impl<'lua> Unpin for AnyUserData<'lua>
impl<'lua> !UnwindSafe for AnyUserData<'lua>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more