mlua_codemp_patch/util/
types.rs

1use std::any::Any;
2use std::os::raw::c_void;
3
4use crate::types::{Callback, CallbackUpvalue};
5
6#[cfg(feature = "async")]
7use crate::types::{AsyncCallback, AsyncCallbackUpvalue, AsyncPollUpvalue};
8
9pub(crate) trait TypeKey: Any {
10    fn type_key() -> *const c_void;
11}
12
13static STRING_TYPE_KEY: u8 = 0;
14
15impl TypeKey for String {
16    #[inline(always)]
17    fn type_key() -> *const c_void {
18        &STRING_TYPE_KEY as *const u8 as *const c_void
19    }
20}
21
22static CALLBACK_TYPE_KEY: u8 = 0;
23
24impl TypeKey for Callback {
25    #[inline(always)]
26    fn type_key() -> *const c_void {
27        &CALLBACK_TYPE_KEY as *const u8 as *const c_void
28    }
29}
30
31static CALLBACK_UPVALUE_TYPE_KEY: u8 = 0;
32
33impl TypeKey for CallbackUpvalue {
34    #[inline(always)]
35    fn type_key() -> *const c_void {
36        &CALLBACK_UPVALUE_TYPE_KEY as *const u8 as *const c_void
37    }
38}
39
40#[cfg(feature = "async")]
41static ASYNC_CALLBACK_TYPE_KEY: u8 = 0;
42
43#[cfg(feature = "async")]
44impl TypeKey for AsyncCallback {
45    #[inline(always)]
46    fn type_key() -> *const c_void {
47        &ASYNC_CALLBACK_TYPE_KEY as *const u8 as *const c_void
48    }
49}
50
51#[cfg(feature = "async")]
52static ASYNC_CALLBACK_UPVALUE_TYPE_KEY: u8 = 0;
53
54#[cfg(feature = "async")]
55impl TypeKey for AsyncCallbackUpvalue {
56    #[inline(always)]
57    fn type_key() -> *const c_void {
58        &ASYNC_CALLBACK_UPVALUE_TYPE_KEY as *const u8 as *const c_void
59    }
60}
61
62#[cfg(feature = "async")]
63static ASYNC_POLL_UPVALUE_TYPE_KEY: u8 = 0;
64
65#[cfg(feature = "async")]
66impl TypeKey for AsyncPollUpvalue {
67    #[inline(always)]
68    fn type_key() -> *const c_void {
69        &ASYNC_POLL_UPVALUE_TYPE_KEY as *const u8 as *const c_void
70    }
71}
72
73#[cfg(feature = "async")]
74static WAKER_TYPE_KEY: u8 = 0;
75
76#[cfg(feature = "async")]
77impl TypeKey for Option<std::task::Waker> {
78    #[inline(always)]
79    fn type_key() -> *const c_void {
80        &WAKER_TYPE_KEY as *const u8 as *const c_void
81    }
82}