1pub use super::*;
2use std::cmp::PartialEq;
3use std::fmt;
4
5impl<P> Clone for ThreadPool<P>
6where P: SyncThreadPool + Sized + Clone
7{
8 fn clone(&self) -> Self {
9 Self {
10 inner: Mutex::new(self.inner.lock().clone())
11 }
12 }
13}
14
15impl<P, Rhs> PartialEq<Rhs> for ThreadPool<P>
16where P: SyncThreadPool + Sized + PartialEq<Rhs>,
17 Rhs: ?Sized
18{
19 fn eq(&self, other: &Rhs) -> bool {
20 self.inner.lock().eq(other)
21 }
22}
23
24
25impl<P> Eq for ThreadPool<P>
26where Self: PartialEq,
27 P: SyncThreadPool + Sized + Eq {}
28
29impl<P> fmt::Debug for ThreadPool<P>
30where P: SyncThreadPool + Sized + fmt::Debug
31{
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 f.debug_struct("ThreadPool")
34 .field("inner", &self.inner.lock())
35 .finish()
36 }
37}
38
39impl<P> From<P> for ThreadPool<P>
40where P: SyncThreadPool + Sized + Eq {
41 fn from(p: P) -> Self {
42 Self::from_threadpool(p)
43 }
44}
45
46#[cfg(feature = "threadpool")]
47impl SyncThreadPool for threadpool::ThreadPool {
48 fn new() -> Self {
49 Self::default()
50 }
51 fn with_thread_count(num_threads: usize) -> Self {
52 Self::new(num_threads)
53 }
54 fn execute<F>(&self, fun: F)
55 where
56 F: FnOnce() + Send + 'static
57 {
58 self.execute(fun);
59 }
60}
61
62#[cfg(feature = "uvth")]
63impl SyncThreadPool for uvth::ThreadPool {
64 fn new() -> Self {
65 uvth::ThreadPoolBuilder::new().build()
66 }
67 fn with_thread_count(num_threads: usize) -> Self {
68 uvth::ThreadPoolBuilder::new().num_threads(num_threads).build()
69 }
70 fn execute<F>(&self, fun: F)
71 where
72 F: FnOnce() + Send + 'static
73 {
74 self.execute(fun);
75 }
76}