Struct AnyUserData

Source
pub struct AnyUserData<'lua>(/* 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.

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>(&self) -> bool
where T: 'static + UserData,

Checks whether the type of this userdata is T.

Source

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.

Source

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.

Source

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.

Source

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§

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<(), Error>

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>, Error>

Performs the conversion.
Source§

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

Source§

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

Performs the conversion.

Auto Trait Implementations§

§

impl<'lua> Freeze for AnyUserData<'lua>

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 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<'lua, T> ToLuaMulti<'lua> for T
where T: ToLua<'lua>,

Source§

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

Performs the conversion.
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> Erased for T