Files
tokio/tokio-threadpool/src/callback.rs
T

28 lines
515 B
Rust
Raw Normal View History

2019-05-14 10:27:36 -07:00
use crate::worker::Worker;
use std::fmt;
use std::sync::Arc;
#[derive(Clone)]
pub(crate) struct Callback {
2019-07-16 14:29:35 -04:00
f: Arc<dyn Fn(&Worker) + Send + Sync>,
}
impl Callback {
pub fn new<F>(f: F) -> Self
2019-02-21 11:56:15 -08:00
where
2019-07-16 14:29:35 -04:00
F: Fn(&Worker) + Send + Sync + 'static,
{
Callback { f: Arc::new(f) }
}
2019-07-16 14:29:35 -04:00
pub fn call(&self, worker: &Worker) {
(self.f)(worker)
}
}
impl fmt::Debug for Callback {
2019-05-14 10:27:36 -07:00
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "Fn")
}
}