Struct AnyUserData
pub struct AnyUserData(pub(crate) ValueRef);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.
§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.
Tuple Fields§
§0: ValueRefImplementations§
§impl AnyUserData
impl AnyUserData
pub fn borrow<T>(&self) -> Result<UserDataRef<T>, Error>where
T: 'static,
pub fn borrow<T>(&self) -> Result<UserDataRef<T>, Error>where
T: 'static,
Borrow this userdata immutably if it is of type T.
§Errors
Returns a UserDataBorrowError if the userdata is already mutably borrowed.
Returns a DataTypeMismatch if the userdata is not of type T or if it’s
scoped.
pub fn borrow_scoped<T, R>(&self, f: impl FnOnce(&T) -> R) -> Result<R, Error>where
T: 'static,
pub fn borrow_scoped<T, R>(&self, f: impl FnOnce(&T) -> R) -> Result<R, Error>where
T: 'static,
Borrow this userdata immutably if it is of type T, passing the borrowed value
to the closure.
This method is the only way to borrow scoped userdata (created inside Lua::scope).
pub fn borrow_mut<T>(&self) -> Result<UserDataRefMut<T>, Error>where
T: 'static,
pub fn borrow_mut<T>(&self) -> Result<UserDataRefMut<T>, Error>where
T: 'static,
Borrow this userdata mutably if it is of type T.
§Errors
Returns a UserDataBorrowMutError if the userdata cannot be mutably borrowed.
Returns a UserDataTypeMismatch if the userdata is not of type T or if it’s
scoped.
pub fn borrow_mut_scoped<T, R>(
&self,
f: impl FnOnce(&mut T) -> R,
) -> Result<R, Error>where
T: 'static,
pub fn borrow_mut_scoped<T, R>(
&self,
f: impl FnOnce(&mut T) -> R,
) -> Result<R, Error>where
T: 'static,
Borrow this userdata mutably if it is of type T, passing the borrowed value
to the closure.
This method is the only way to borrow scoped userdata (created inside Lua::scope).
pub fn take<T>(&self) -> Result<T, Error>where
T: 'static,
pub fn take<T>(&self) -> Result<T, Error>where
T: 'static,
Takes the value out of this userdata.
Sets the special “destructed” metatable that prevents any further operations with this userdata.
Keeps associated user values unchanged (they will be collected by Lua’s GC).
pub fn destroy(&self) -> Result<(), Error>
pub fn destroy(&self) -> Result<(), Error>
Destroys this userdata.
This is similar to AnyUserData::take, but it doesn’t require a type.
This method works for non-scoped userdata only.
pub fn set_user_value(&self, v: impl IntoLua) -> Result<(), Error>
pub fn set_user_value(&self, v: impl IntoLua) -> Result<(), Error>
Sets an associated value to this AnyUserData.
The value may be any Lua value whatsoever, and can be retrieved with user_value.
This is the same as calling set_nth_user_value with n set to 1.
pub fn user_value<V>(&self) -> Result<V, Error>where
V: FromLua,
pub fn user_value<V>(&self) -> Result<V, Error>where
V: FromLua,
Returns an associated value set by set_user_value.
This is the same as calling nth_user_value with n set to 1.
pub fn set_nth_user_value(&self, n: usize, v: impl IntoLua) -> Result<(), Error>
pub fn set_nth_user_value(&self, n: usize, v: impl IntoLua) -> Result<(), Error>
Sets an associated nth value to this AnyUserData.
The value may be any Lua value whatsoever, and can be retrieved with nth_user_value.
n starts from 1 and can be up to 65535.
This is supported for all Lua versions using a wrapping table.
pub fn nth_user_value<V>(&self, n: usize) -> Result<V, Error>where
V: FromLua,
pub fn nth_user_value<V>(&self, n: usize) -> Result<V, Error>where
V: FromLua,
Returns an associated nth value set by set_nth_user_value.
n starts from 1 and can be up to 65535.
This is supported for all Lua versions using a wrapping table.
pub fn set_named_user_value(
&self,
name: &str,
v: impl IntoLua,
) -> Result<(), Error>
pub fn set_named_user_value( &self, name: &str, v: impl IntoLua, ) -> Result<(), Error>
Sets an associated value to this AnyUserData by name.
The value can be retrieved with named_user_value.
pub fn named_user_value<V>(&self, name: &str) -> Result<V, Error>where
V: FromLua,
pub fn named_user_value<V>(&self, name: &str) -> Result<V, Error>where
V: FromLua,
Returns an associated value by name set by set_named_user_value.
pub fn metatable(&self) -> Result<UserDataMetatable, Error>
pub fn metatable(&self) -> Result<UserDataMetatable, Error>
Returns a metatable of this AnyUserData.
Returned UserDataMetatable object wraps the original metatable and
provides safe access to its methods.
For T: 'static returned metatable is shared among all instances of type T.
pub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
Converts this userdata to a generic C pointer.
There is no way to convert the pointer back to its original value.
Typically this function is used only for hashing and debug information.
§impl AnyUserData
impl AnyUserData
pub fn wrap<T>(data: T) -> impl IntoLuawhere
T: MaybeSend + 'static,
pub fn wrap<T>(data: T) -> impl IntoLuawhere
T: MaybeSend + 'static,
Wraps any Rust type, returning an opaque type that implements IntoLua trait.
This function uses Lua::create_any_userdata under the hood.
Trait Implementations§
§impl Clone for AnyUserData
impl Clone for AnyUserData
§fn clone(&self) -> AnyUserData
fn clone(&self) -> AnyUserData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for AnyUserData
impl Debug for AnyUserData
§impl FromLua for AnyUserData
impl FromLua for AnyUserData
§impl IntoLua for &AnyUserData
impl IntoLua for &AnyUserData
§impl IntoLua for AnyUserData
impl IntoLua for AnyUserData
§impl ObjectLike for AnyUserData
impl ObjectLike for AnyUserData
§fn get<V>(&self, key: impl IntoLua) -> Result<V, Error>where
V: FromLua,
fn get<V>(&self, key: impl IntoLua) -> Result<V, Error>where
V: FromLua,
key from the object, assuming it has __index metamethod.§fn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<(), Error>
fn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<(), Error>
key in the object, assuming it has __newindex metamethod.§fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>where
R: FromLuaMulti,
fn call<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>where
R: FromLuaMulti,
__call metamethod. Read more§fn call_method<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> Result<R, Error>where
R: FromLuaMulti,
fn call_method<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> Result<R, Error>where
R: FromLuaMulti,
name from the object and calls it,
passing the object itself along with args as function arguments.§fn call_function<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> Result<R, Error>where
R: FromLuaMulti,
fn call_function<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> Result<R, Error>where
R: FromLuaMulti,
name from the object and calls it,
passing args as function arguments. Read more§impl PartialEq for AnyUserData
impl PartialEq for AnyUserData
impl StructuralPartialEq for AnyUserData
Auto Trait Implementations§
impl Freeze for AnyUserData
impl !RefUnwindSafe for AnyUserData
impl !Send for AnyUserData
impl !Sync for AnyUserData
impl Unpin for AnyUserData
impl !UnwindSafe for AnyUserData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FromLuaMulti for Twhere
T: FromLua,
impl<T> FromLuaMulti for Twhere
T: FromLua,
§fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_args( args: MultiValue, i: usize, to: Option<&str>, lua: &Lua, ) -> Result<T, Error>
unsafe fn from_stack_multi(nvals: i32, lua: &RawLua) -> Result<T, Error>
unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &RawLua, ) -> Result<T, Error>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoLuaMulti for Twhere
T: IntoLua,
impl<T> IntoLuaMulti for Twhere
T: IntoLua,
§fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue, Error>
unsafe fn push_into_stack_multi(self, lua: &RawLua) -> Result<i32, Error>
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§type Error = Infallible
type Error = Infallible
Result.§fn into_result(self) -> Result<T, <T as IntoResult<T>>::Error>
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Error>
Result.§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more