pub struct Thread { /* private fields */ }Expand description
A handle to a Lua thread (coroutine). Mirrors mlua::Thread.
Under the send feature it is Send but never Sync — see
[crate::sync::NotSync].
Implementations§
Source§impl Thread
impl Thread
Sourcepub fn state(&self) -> *mut lua_State
pub fn state(&self) -> *mut lua_State
The raw coroutine state pointer. Mirrors mlua::Thread::state.
Sourcepub fn resume<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>where
R: FromLuaMulti,
pub fn resume<R>(&self, args: impl IntoLuaMulti) -> Result<R, Error>where
R: FromLuaMulti,
Resume the coroutine, passing args and converting its yielded/returned
values to R. Mirrors mlua::Thread::resume.
Returns Error::CoroutineUnresumable if the thread has finished,
errored, or is otherwise not resumable.
Sourcepub fn resume_error<R>(&self, error: impl IntoLua) -> Result<R, Error>where
R: FromLuaMulti,
pub fn resume_error<R>(&self, error: impl IntoLua) -> Result<R, Error>where
R: FromLuaMulti,
Resume the coroutine, immediately raising error inside it.
Mirrors mlua::Thread::resume_error (a Luau extension).
Sourcepub fn status(&self) -> ThreadStatus
pub fn status(&self) -> ThreadStatus
The thread’s status. Mirrors mlua::Thread::status.
Sourcepub fn is_resumable(&self) -> bool
pub fn is_resumable(&self) -> bool
Whether the thread can be resumed. Mirrors mlua::Thread::is_resumable.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the thread is currently running. Mirrors mlua::Thread::is_running.
Sourcepub fn is_normal(&self) -> bool
pub fn is_normal(&self) -> bool
Whether the thread is active but not running. Mirrors
mlua::Thread::is_normal.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether the thread has finished executing. Mirrors
mlua::Thread::is_finished.
Sourcepub fn is_error(&self) -> bool
pub fn is_error(&self) -> bool
Whether the thread raised an error. Mirrors mlua::Thread::is_error.
Sourcepub fn reset(&self, func: Function) -> Result<(), Error>
pub fn reset(&self, func: Function) -> Result<(), Error>
Reset the thread to a fresh state and install func as its body.
Mirrors mlua::Thread::reset (Luau semantics: any non-running thread can
be reset).
Sourcepub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
A raw pointer identifying this thread. Mirrors mlua::Thread::to_pointer.
Source§impl Thread
impl Thread
Sourcepub fn into_async<R>(
self,
args: impl IntoLuaMulti,
) -> Result<AsyncThread<R>, Error>where
R: FromLuaMulti,
pub fn into_async<R>(
self,
args: impl IntoLuaMulti,
) -> Result<AsyncThread<R>, Error>where
R: FromLuaMulti,
Convert this (resumable) thread into an
AsyncThread that implements
Future and
Stream.
Mirrors mlua::Thread::into_async. args are passed to the coroutine on
its first resume. As a Future the thread is driven to completion and
resolves to its final return value(s); as a Stream each
coroutine.yield produces an item.