Skip to main content

mlua_luau_scheduler/threads/
id.rs

1use std::{
2    ffi::c_void,
3    hash::{Hash, Hasher},
4};
5
6use mlua::prelude::*;
7
8/**
9    Opaque and unique ID representing a [`LuaThread`].
10
11    Typically used for associating metadata with a thread in a structure such as a `HashMap<ThreadId, ...>`.
12
13    Note that holding a `ThreadId` does not prevent the thread from being garbage collected.
14    The actual thread may or may not still exist and be active at any given point in time.
15*/
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct ThreadId {
18    inner: *const c_void,
19}
20
21impl From<&LuaThread> for ThreadId {
22    fn from(thread: &LuaThread) -> Self {
23        Self {
24            inner: thread.to_pointer(),
25        }
26    }
27}
28
29impl Hash for ThreadId {
30    fn hash<H: Hasher>(&self, state: &mut H) {
31        self.inner.hash(state);
32    }
33}