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§

source§

impl<'lua> AnyUserData<'lua>

source

pub fn is<T: 'static + UserData>(&self) -> bool

Checks whether the type of this userdata is T.

source

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.

source

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.

source

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)

source

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.

source

pub fn get_user_value<V: FromLua<'lua>>(&self) -> Result<V>

Returns an associated value set by set_user_value.

source

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§

source§

impl<'lua> Clone for AnyUserData<'lua>

source§

fn clone(&self) -> AnyUserData<'lua>

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<'lua> Debug for AnyUserData<'lua>

source§

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

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

impl<'lua> FromLua<'lua> for AnyUserData<'lua>

source§

fn from_lua(value: Value<'lua>, _: Context<'lua>) -> Result<AnyUserData<'lua>>

Performs the conversion.
source§

impl<'lua> ToLua<'lua> for AnyUserData<'lua>

source§

fn to_lua(self, _: Context<'lua>) -> Result<Value<'lua>>

Performs the conversion.

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'lua, T> FromLuaMulti<'lua> for Twhere T: FromLua<'lua>,

source§

fn from_lua_multi( values: MultiValue<'lua>, lua: Context<'lua> ) -> Result<T, Error>

Performs the conversion. Read more
source§

impl<T, U> Into<U> for Twhere 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<'lua, T> ToLuaMulti<'lua> for Twhere T: ToLua<'lua>,

source§

fn to_lua_multi(self, lua: Context<'lua>) -> Result<MultiValue<'lua>, Error>

Performs the conversion.
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.