1use std::future::Future;
2use std::io::Result;
3use std::marker::PhantomData;
4
5#[inline(always)]
11pub fn spawn_local<F>(f: F)
12where
13 F: Future<Output = ()> + 'static,
14{
15 crate::imp::spawn_local(f);
16}
17
18#[derive(Debug)]
20pub struct RuntimeBuilder {
21 worker_threads: usize,
22}
23
24impl Default for RuntimeBuilder {
25 fn default() -> Self {
26 Self {
27 worker_threads: crate::imp::get_default_runtime_size(),
28 }
29 }
30}
31
32impl RuntimeBuilder {
33 pub fn new() -> Self {
35 Self::default()
36 }
37
38 pub fn worker_threads(&mut self, val: usize) -> &mut Self {
48 self.worker_threads = val;
49
50 self
51 }
52
53 pub fn build(&mut self) -> Result<Runtime> {
55 Ok(Runtime {
56 inner: crate::imp::Runtime::new(self.worker_threads)?,
57 })
58 }
59}
60
61#[derive(Debug, Clone, Default)]
63pub struct Runtime {
64 inner: crate::imp::Runtime,
65}
66
67impl Runtime {
68 pub fn builder() -> RuntimeBuilder {
70 RuntimeBuilder::new()
71 }
72
73 #[inline(always)]
79 pub fn spawn_pinned<F, Fut>(&self, create_task: F)
80 where
81 F: FnOnce() -> Fut,
82 F: Send + 'static,
83 Fut: Future<Output = ()> + 'static,
84 {
85 self.inner.spawn_pinned(create_task);
86 }
87}
88
89#[derive(Debug, Clone)]
93pub struct LocalHandle {
94 inner: crate::imp::LocalHandle,
95 _marker: PhantomData<*const ()>,
97}
98
99impl LocalHandle {
100 pub fn current() -> Self {
106 let inner = crate::imp::LocalHandle::current();
107
108 Self {
109 inner,
110 _marker: PhantomData,
111 }
112 }
113
114 pub fn try_current() -> Option<Self> {
118 let inner = crate::imp::LocalHandle::try_current()?;
119
120 Some(Self {
121 inner,
122 _marker: PhantomData,
123 })
124 }
125
126 #[inline(always)]
128 pub fn spawn_local<F>(&self, f: F)
129 where
130 F: Future<Output = ()> + 'static,
131 {
132 self.inner.spawn_local(f);
133 }
134}