sapi_lite/tokio/
rt.rs

1#[cfg_attr(docsrs, doc(cfg(feature = "tokio-rt")))]
2/// An extension for [`tokio::runtime::Builder`] to enable SAPI.
3///
4/// This trait is [sealed](https://rust-lang.github.io/api-guidelines/future-proofing.html).
5pub trait BuilderExt: private::Sealed {
6    /// Ensures that every thread spawned by the runtime will initialize SAPI when started and
7    /// deinitialize it when stopped.
8    fn enable_sapi(&mut self) -> &mut Self;
9}
10
11impl BuilderExt for tokio::runtime::Builder {
12    fn enable_sapi(&mut self) -> &mut Self {
13        self.on_thread_start(|| {
14            let _ = crate::initialize();
15        })
16        .on_thread_stop(crate::finalize)
17    }
18}
19
20mod private {
21    pub trait Sealed {}
22    impl Sealed for tokio::runtime::Builder {}
23}