pub struct AnyUserData { /* private fields */ }Implementations§
Source§impl AnyUserData
impl AnyUserData
pub fn borrow<T>(&self) -> Result<Ref<'_, T>>where
T: 'static,
pub fn borrow_mut<T>(&self) -> Result<RefMut<'_, T>>where
T: 'static,
pub fn with_borrow<T, R>(&self, f: impl FnOnce(&T) -> R) -> Result<R>where
T: 'static,
pub fn with_borrow_mut<T, R>(&self, f: impl FnOnce(&mut T) -> R) -> Result<R>where
T: 'static,
Sourcepub fn scoped_borrow<T, R>(&self, f: impl FnOnce(&T) -> R) -> Result<R>where
T: 'static,
pub fn scoped_borrow<T, R>(&self, f: impl FnOnce(&T) -> R) -> Result<R>where
T: 'static,
Rust-side shared borrow of a [Scope::create_userdata] payload. Routes
through the scoped cell, so calls after the scope has dropped fail with
the same “no longer valid” error a Lua method call would see, instead
of returning a stale reference.
Sourcepub fn scoped_borrow_mut<T, R>(&self, f: impl FnOnce(&mut T) -> R) -> Result<R>where
T: 'static,
pub fn scoped_borrow_mut<T, R>(&self, f: impl FnOnce(&mut T) -> R) -> Result<R>where
T: 'static,
Rust-side exclusive borrow of a [Scope::create_userdata] payload. Same
invalidation guarantees as Self::scoped_borrow.
Sourcepub fn delegate<P, S, F>(&self, lua: &Lua, accessor: F) -> Result<AnyUserData>
pub fn delegate<P, S, F>(&self, lua: &Lua, accessor: F) -> Result<AnyUserData>
Create a sub-userdata in the same scope that re-acquires &mut S
from this userdata’s payload via accessor on every method call.
The sub-userdata holds no long-lived &mut S: every Lua method call
borrows the parent (mut), applies accessor, runs the method,
releases. If a script tries to call a parent method while inside a
sub-userdata method body, the inner try_borrow_mut surfaces the
same “already borrowed” error path scoped cells already use.
Receiver must be a Scope::create_userdata_ref_mut userdata of
type P, or another delegated userdata of type P (chains
compose).
Scope invalidation propagates: when the originating scope drops, both the parent and every delegated descendant become invalid.
Sourcepub fn delegate_ref<P, S, F>(
&self,
lua: &Lua,
accessor: F,
) -> Result<AnyUserData>
pub fn delegate_ref<P, S, F>( &self, lua: &Lua, accessor: F, ) -> Result<AnyUserData>
Shared counterpart to Self::delegate. The accessor takes &P and
returns &S, the parent is borrowed shared per call, and the resulting
sub-userdata is read-only: a mutating method on it fails with a clean
runtime error. Used for &self -> &S accessors.
Source§impl AnyUserData
impl AnyUserData
Sourcepub fn to_pointer(&self) -> Result<usize>
pub fn to_pointer(&self) -> Result<usize>
A stable identity token for this userdata. See Table::to_pointer.
Source§impl AnyUserData
impl AnyUserData
Sourcepub fn set_user_value<V: IntoLua>(&self, n: usize, value: V) -> Result<()>
pub fn set_user_value<V: IntoLua>(&self, n: usize, value: V) -> Result<()>
Set the n-th uservalue (1-based). The userdata must have been created
with at least n slots via Lua::create_userdata_with_uservalues;
this never grows the slot vector, so an out-of-range n errors. The
store is GC-write-barriered by the VM (set_i_uservalue).
Sourcepub fn user_value<V: FromLua>(&self, n: usize) -> Result<V>
pub fn user_value<V: FromLua>(&self, n: usize) -> Result<V>
Read the n-th uservalue (1-based); nil if unset or out of range.
Trait Implementations§
Source§impl Clone for AnyUserData
impl Clone for AnyUserData
Source§fn clone(&self) -> AnyUserData
fn clone(&self) -> AnyUserData
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more