1#![doc = include_str!("../README.md")]
2
3use std::fmt::{Debug, Formatter};
4
5pub use crate::handle::TokioEnterGuard;
6
7mod handle;
8fn get_data() -> u64 {
9 get_features as *const () as u64
10}
11
12fn get_features() -> u16 {
13 0
14}
15
16#[derive(Clone)]
17#[repr(C)]
18pub struct SharedTokioHandle {
19 data: u64,
20 features: u16,
21 handle: ::tokio::runtime::Handle,
22}
23impl Debug for SharedTokioHandle {
24 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
25 let mut dbg = f.debug_struct("SharedTokioHandle");
26
27 dbg.field("data", &format_args!("{:p}", self.data as *const ()))
28 .field("features", &self.features);
29 dbg.finish()
30 }
31}
32impl SharedTokioHandle {
33 pub fn new() -> Self {
34 SharedTokioHandle {
35 data: get_data(),
36 features: get_features(),
37 handle: tokio::runtime::Handle::current(),
38 }
39 }
40
41 #[inline(never)]
42 pub fn enter(&self) -> TokioEnterGuard {
43 TokioEnterGuard::new(self.handle.enter())
44 }
45}
46
47#[no_mangle]
48#[inline(never)]
49pub fn setup_shared_tokio_ref(handle: &SharedTokioHandle) -> TokioEnterGuard {
50 handle.enter()
51}