mlua_luau_scheduler/
thread_id.rs

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