1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::thread;
#[cfg(feature = "threadpool")]
use threadpool;
pub trait Spawner {
fn spawn<F>(&self, f: F) where F: FnOnce() + Send + 'static;
}
pub struct ThreadSpawner;
impl Spawner for ThreadSpawner {
fn spawn<F>(&self, f: F)
where F: FnOnce() + Send + 'static
{
let _ = thread::spawn(f);
}
}
#[cfg(feature = "threadpool")]
impl Spawner for threadpool::ThreadPool {
fn spawn<F>(&self, f: F)
where F: FnOnce() + Send + 'static
{
self.execute(f)
}
}