diff --git a/examples/vpv.rs b/examples/vpv.rs index 7f63bbb..ce5f8d9 100644 --- a/examples/vpv.rs +++ b/examples/vpv.rs @@ -137,7 +137,7 @@ cargo run --example vpv /dev/null", } // When we're done, shut down the application - cb_sink.send(Box::new(|s: &mut Cursive| s.quit())).unwrap(); + cb_sink.send(Box::new(Cursive::quit)).unwrap(); }); siv.set_autorefresh(true); } diff --git a/src/cursive.rs b/src/cursive.rs index 495da61..970bd41 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -43,8 +43,8 @@ pub struct Cursive { backend: Box, - cb_source: Receiver>, - cb_sink: Sender>, + cb_source: Receiver>, + cb_sink: Sender>, // User-provided data. user_data: Box, @@ -57,25 +57,7 @@ pub struct Cursive { pub type ScreenId = usize; /// Convenient alias to the result of `Cursive::cb_sink`. -pub type CbSink = Sender>; - -/// Asynchronous callback function trait. -/// -/// Every `FnOnce(&mut Cursive) -> () + Send` automatically -/// implements this. -/// -/// This is a workaround only because `Box` is not -/// working and `FnBox` is unstable. -pub trait CbFunc: Send { - /// Calls the function. - fn call_box(self: Box, _: &mut Cursive); -} - -impl () + Send> CbFunc for F { - fn call_box(self: Box, siv: &mut Cursive) { - (*self)(siv) - } -} +pub type CbSink = Sender>; cfg_if::cfg_if! { if #[cfg(feature = "blt-backend")] { @@ -330,7 +312,7 @@ impl Cursive { /// let mut siv = Cursive::dummy(); /// /// // quit() will be called during the next event cycle - /// siv.cb_sink().send(Box::new(|s: &mut Cursive| s.quit())).unwrap(); + /// siv.cb_sink().send(Box::new(|s| s.quit())).unwrap(); /// # } /// ``` pub fn cb_sink(&self) -> &CbSink { @@ -877,7 +859,7 @@ impl Cursive { // Then, handle any available callback while let Ok(cb) = self.cb_source.try_recv() { boring = false; - cb.call_box(self); + cb(self); if !self.running { return true; diff --git a/src/lib.rs b/src/lib.rs index e75f110..4326cad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,7 +101,7 @@ mod utf8; pub mod backend; -pub use self::cursive::{CbFunc, CbSink, Cursive, ScreenId}; +pub use self::cursive::{CbSink, Cursive, ScreenId}; pub use self::printer::Printer; pub use self::rect::Rect; pub use self::vec::Vec2;