Struct mod_memoize::Memoized
source · pub struct Memoized {
pub to_value: Arc<dyn Fn(&Lua) -> Result<Value<'_>> + Send + Sync>,
}
Expand description
Memoized is a helper type that allows native Rust types to be captured in memoization caches. Unfortunately, we cannot automatically make that work for all UserData that are exported to lua, but we can make it simple for a type to opt-in to that behavior.
When you impl UserData for your type, you can call
Memoized::impl_memoize(methods)
from your add_methods impl.
That will add a metamethod to your UserData type that will clone your
value and wrap it into a Memoized wrapper.
Since Clone is used, it is recommended that you use an Arc inside your type to avoid making large or expensive clones.
Fields§
§to_value: Arc<dyn Fn(&Lua) -> Result<Value<'_>> + Send + Sync>
Implementations§
Trait Implementations§
source§impl UserData for Memoized
impl UserData for Memoized
§fn add_fields<'lua, F>(fields: &mut F)where
F: UserDataFields<'lua, Self>,
fn add_fields<'lua, F>(fields: &mut F)where
F: UserDataFields<'lua, Self>,
Adds custom fields specific to this userdata.
§fn add_methods<'lua, M>(methods: &mut M)where
M: UserDataMethods<'lua, Self>,
fn add_methods<'lua, M>(methods: &mut M)where
M: UserDataMethods<'lua, Self>,
Adds custom methods and operators specific to this userdata.
Auto Trait Implementations§
impl Freeze for Memoized
impl !RefUnwindSafe for Memoized
impl Send for Memoized
impl Sync for Memoized
impl Unpin for Memoized
impl !UnwindSafe for Memoized
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<'lua, T> FromLuaMulti<'lua> for Twhere
T: FromLua<'lua>,
impl<'lua, T> FromLuaMulti<'lua> for Twhere
T: FromLua<'lua>,
§fn from_lua_multi(values: MultiValue<'lua>, lua: &'lua Lua) -> Result<T, Error>
fn from_lua_multi(values: MultiValue<'lua>, lua: &'lua Lua) -> Result<T, Error>
Performs the conversion. Read more
fn from_lua_args( args: MultiValue<'lua>, i: usize, to: Option<&str>, lua: &'lua Lua, ) -> Result<T, Error>
unsafe fn from_stack_multi(nvals: i32, lua: &'lua Lua) -> Result<T, Error>
unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &'lua Lua, ) -> 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>
§impl<'lua, T> IntoLua<'lua> for Twhere
T: UserData + MaybeSend + 'static,
impl<'lua, T> IntoLua<'lua> for Twhere
T: UserData + MaybeSend + 'static,
§impl<'lua, T> IntoLuaMulti<'lua> for Twhere
T: IntoLua<'lua>,
impl<'lua, T> IntoLuaMulti<'lua> for Twhere
T: IntoLua<'lua>,
§fn into_lua_multi(self, lua: &'lua Lua) -> Result<MultiValue<'lua>, Error>
fn into_lua_multi(self, lua: &'lua Lua) -> Result<MultiValue<'lua>, Error>
Performs the conversion.