[][src]Struct mlua::Scope

pub struct Scope<'lua, 'scope> { /* fields omitted */ }

Constructed by the Lua::scope method, allows temporarily creating Lua userdata and callbacks that are not required to be Send or 'static.

See Lua::scope for more details.

Implementations

impl<'lua, 'scope> Scope<'lua, 'scope>[src]

pub fn create_function<'callback, A, R, F>(
    &'callback self,
    func: F
) -> Result<Function<'lua>> where
    A: FromLuaMulti<'callback>,
    R: ToLuaMulti<'callback>,
    F: 'scope + Fn(&'callback Lua, A) -> Result<R>, 
[src]

Wraps a Rust function or closure, creating a callable Lua function handle to it.

This is a version of Lua::create_function that creates a callback which expires on scope drop. See Lua::scope for more details.

pub fn create_function_mut<'callback, A, R, F>(
    &'callback self,
    func: F
) -> Result<Function<'lua>> where
    A: FromLuaMulti<'callback>,
    R: ToLuaMulti<'callback>,
    F: 'scope + FnMut(&'callback Lua, A) -> Result<R>, 
[src]

Wraps a Rust mutable closure, creating a callable Lua function handle to it.

This is a version of Lua::create_function_mut that creates a callback which expires on scope drop. See Lua::scope and Scope::create_function for more details.

pub fn create_async_function<'callback, A, R, F, FR>(
    &'callback self,
    func: F
) -> Result<Function<'lua>> where
    A: FromLuaMulti<'callback>,
    R: ToLuaMulti<'callback>,
    F: 'scope + Fn(&'callback Lua, A) -> FR,
    FR: 'callback + Future<Output = Result<R>>, 
[src]

This is supported on crate feature async only.

Wraps a Rust async function or closure, creating a callable Lua function handle to it.

This is a version of Lua::create_async_function that creates a callback which expires on scope drop. See Lua::scope and Lua::async_scope for more details.

Requires feature = "async"

pub fn create_userdata<T>(&self, data: T) -> Result<AnyUserData<'lua>> where
    T: 'static + UserData
[src]

Create a Lua userdata object from a custom userdata type.

This is a version of Lua::create_userdata that creates a userdata which expires on scope drop, and does not require that the userdata type be Send (but still requires that the UserData be 'static). See Lua::scope for more details.

pub fn create_ser_userdata<T>(&self, data: T) -> Result<AnyUserData<'lua>> where
    T: 'static + UserData + Serialize
[src]

This is supported on crate feature serialize only.

Create a Lua userdata object from a custom serializable userdata type.

This is a version of Lua::create_ser_userdata that creates a userdata which expires on scope drop, and does not require that the userdata type be Send (but still requires that the UserData be 'static). See Lua::scope for more details.

Requires feature = "serialize"

pub fn create_nonstatic_userdata<T>(&self, data: T) -> Result<AnyUserData<'lua>> where
    T: 'scope + UserData
[src]

Create a Lua userdata object from a custom userdata type.

This is a version of Lua::create_userdata that creates a userdata which expires on scope drop, and does not require that the userdata type be Send or 'static. See Lua::scope for more details.

Lifting the requirement that the UserData type be 'static comes with some important limitations, so if you only need to eliminate the Send requirement, it is probably better to use Scope::create_userdata instead.

The main limitation that comes from using non-'static userdata is that the produced userdata will no longer have a TypeId associated with it, becuase TypeId can only work for 'static types. This means that it is impossible, once the userdata is created, to get a reference to it back out of an AnyUserData handle. This also implies that the "function" type methods that can be added via UserDataMethods (the ones that accept AnyUserData as a first parameter) are vastly less useful. Also, there is no way to re-use a single metatable for multiple non-'static types, so there is a higher cost associated with creating the userdata metatable each time a new userdata is created.

Trait Implementations

impl<'lua, 'scope> Drop for Scope<'lua, 'scope>[src]

Auto Trait Implementations

impl<'lua, 'scope> !RefUnwindSafe for Scope<'lua, 'scope>[src]

impl<'lua, 'scope> !Send for Scope<'lua, 'scope>[src]

impl<'lua, 'scope> !Sync for Scope<'lua, 'scope>[src]

impl<'lua, 'scope> Unpin for Scope<'lua, 'scope>[src]

impl<'lua, 'scope> !UnwindSafe for Scope<'lua, 'scope>[src]

Blanket Implementations

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

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

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

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

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

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.

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.