Struct mlua::prelude::LuaAnyUserData[][src]

pub struct LuaAnyUserData<'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

impl<'lua> AnyUserData<'lua>[src]

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

Checks whether the type of this userdata is T.

pub fn borrow<T: 'static + UserData>(&self) -> Result<Ref<'_, T>>[src]

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.

pub fn borrow_mut<T: 'static + UserData>(&self) -> Result<RefMut<'_, T>>[src]

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.

pub fn set_user_value<V: ToLua<'lua>>(&self, v: V) -> Result<()>[src]

Sets an associated value to this AnyUserData.

The value may be any Lua value whatsoever, and can be retrieved with get_user_value. As Lua < 5.3 allows to store only tables, the value will be stored in a table at index 1.

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

Returns an associated value set by set_user_value.

For Lua < 5.3 the value will be automatically extracted from the table wrapper from index 1.

pub fn get_metatable(&self) -> Result<UserDataMetatable<'lua>>[src]

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

impl<'lua> AsRef<AnyUserData<'lua>> for AnyUserData<'lua>[src]

fn as_ref(&self) -> &Self[src]

Performs the conversion.

impl<'lua> Clone for AnyUserData<'lua>[src]

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

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'lua> Debug for AnyUserData<'lua>[src]

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

Formats the value using the given formatter. Read more

impl<'lua> FromLua<'lua> for AnyUserData<'lua>[src]

fn from_lua(value: Value<'lua>, _: &'lua Lua) -> Result<AnyUserData<'lua>>[src]

Performs the conversion.

impl<'lua> PartialEq<AnyUserData<'lua>> for AnyUserData<'lua>[src]

fn eq(&self, other: &Self) -> bool[src]

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'lua> Serialize for AnyUserData<'lua>[src]

fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error> where
    S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

impl<'lua> ToLua<'lua> for AnyUserData<'lua>[src]

fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Serialize for T where
    T: Serialize + ?Sized
[src]

pub fn erased_serialize(
    &self,
    serializer: &mut dyn Serializer
) -> Result<Ok, Error>
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.