use static_assertions::assert_not_impl_any;
#[derive(Clone, Copy)]
pub struct MainThreadToken {
_dont_send_me: std::marker::PhantomData<*const ()>,
}
impl MainThreadToken {
pub fn i_promise_i_am_on_the_main_thread() -> Self {
#[cfg(not(target_arch = "wasm32"))]
debug_assert_eq!(
std::thread::current().name(),
Some("main"),
"DEBUG ASSERT: Trying to construct a MainThreadToken on a thread that is not the main thread!"
);
Self {
_dont_send_me: std::marker::PhantomData,
}
}
pub fn i_promise_i_am_only_using_this_for_a_test() -> Self {
Self {
_dont_send_me: std::marker::PhantomData,
}
}
#[cfg(feature = "egui")]
pub fn from_egui_ui(_ui: &egui::Ui) -> Self {
Self::i_promise_i_am_on_the_main_thread()
}
}
assert_not_impl_any!(MainThreadToken: Send, Sync);
assert_not_impl_any!(&MainThreadToken: Send, Sync);