diff --git a/Cargo.toml b/Cargo.toml index f23886ddb..dff66841c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ embed-resource = "1.1" [dependencies] base91 = { path = "base91" } bitflags = "1.0" -boxfnonce = "0.1" clipboard = "0.5" dirs = "1.0" euclid = "0.19" diff --git a/promise/Cargo.toml b/promise/Cargo.toml index 5c2bf03ee..576be8f61 100644 --- a/promise/Cargo.toml +++ b/promise/Cargo.toml @@ -6,5 +6,4 @@ edition = "2018" [dependencies] failure = "0.1" -boxfnonce = "0.1" rayon = "1.0" diff --git a/promise/src/lib.rs b/promise/src/lib.rs index bea31bf78..c03718642 100644 --- a/promise/src/lib.rs +++ b/promise/src/lib.rs @@ -1,9 +1,8 @@ -use boxfnonce::SendBoxFnOnce; -use failure::Error; +use failure::{Error, Fallible}; use std::sync::{Arc, Condvar, Mutex}; -type NextFunc = SendBoxFnOnce<'static, (Result,)>; -pub type SpawnFunc = SendBoxFnOnce<'static, ()>; +type NextFunc = Box) + Send>; +pub type SpawnFunc = Box; pub trait Executor: Send { fn execute(&self, f: SpawnFunc); @@ -32,7 +31,7 @@ impl RayonExecutor { impl Executor for RayonExecutor { fn execute(&self, f: SpawnFunc) { - rayon::spawn(|| f.call()); + rayon::spawn(|| f()); } fn clone_executor(&self) -> Box { Box::new(RayonExecutor::new()) @@ -103,7 +102,7 @@ impl Promise { PromiseState::Waiting(core) => { let mut locked = core.data.lock().unwrap(); match locked.propagate.take() { - Some(func) => func.call(result), + Some(func) => func(result), None => locked.result = Some(result), } core.cond.notify_one(); @@ -153,10 +152,10 @@ impl Future { let mut promise = Promise::new(); let future = promise.get_future().unwrap(); - let func = SendBoxFnOnce::from(f); - let promise_chain = NextFunc::from(move |result| promise.result(result)); - executor.execute(SpawnFunc::from(move || { - let future = func.call().into(); + let func = Box::new(f); + let promise_chain = Box::new(move |result| promise.result(result)); + executor.execute(Box::new(move || { + let future = func().into(); future.chain(promise_chain); })); future @@ -165,12 +164,12 @@ impl Future { fn chain(self, f: NextFunc) { match self.state { FutureState::Ready(result) => { - f.call(result); + f(result); } FutureState::Waiting(core) => { let mut locked = core.data.lock().unwrap(); if let Some(result) = locked.result.take() { - f.call(result); + f(result); } else { locked.propagate = Some(f); } @@ -207,12 +206,12 @@ impl Future { { let mut promise = Promise::new(); let future = promise.get_future().unwrap(); - let func = SendBoxFnOnce::from(f); + let func = Box::new(f); - let promise_chain = NextFunc::from(move |result| promise.result(result)); + let promise_chain = Box::new(move |result| promise.result(result)); - self.chain(SendBoxFnOnce::from(move |result| { - let future = func.call(result).into(); + self.chain(Box::new(move |result| { + let future = func(result).into(); future.chain(promise_chain); })); future @@ -233,13 +232,13 @@ impl Future { { let mut promise = Promise::new(); let future = promise.get_future().unwrap(); - let func = SendBoxFnOnce::from(f); + let func = Box::new(f); - let promise_chain = NextFunc::from(move |result| promise.result(result)); + let promise_chain = Box::new(move |result| promise.result(result)); - self.chain(SendBoxFnOnce::from(move |result| { + self.chain(Box::new(move |result| { let future = match result { - Ok(value) => func.call(value).into(), + Ok(value) => func(value).into(), Err(err) => Err(err).into(), }; future.chain(promise_chain); @@ -261,14 +260,14 @@ impl Future { { let mut promise = Promise::new(); let future = promise.get_future().unwrap(); - let func = SendBoxFnOnce::from(f); + let func = Box::new(f); - let promise_chain = NextFunc::from(move |result| promise.result(result)); + let promise_chain = Box::new(move |result| promise.result(result)); - self.chain(SendBoxFnOnce::from(move |result| { + self.chain(Box::new(move |result| { let future = match result { Ok(value) => Ok(value).into(), - Err(err) => func.call(err).into(), + Err(err) => func(err).into(), }; future.chain(promise_chain); })); diff --git a/src/frontend/glium/glutinloop.rs b/src/frontend/glium/glutinloop.rs index ca240d046..06e112b2e 100644 --- a/src/frontend/glium/glutinloop.rs +++ b/src/frontend/glium/glutinloop.rs @@ -329,7 +329,7 @@ impl GuiEventLoop { fn process_gui_exec(&self) -> Result<(), Error> { while let Some(func) = self.gui_thread_sends.borrow_mut().pop_front() { - func.call(); + func(); } let start = SystemTime::now(); @@ -344,7 +344,7 @@ impl GuiEventLoop { _ => {} } match self.gui_rx.try_recv() { - Ok(func) => func.call(), + Ok(func) => func(), Err(TryRecvError::Empty) => return Ok(()), Err(err) => bail!("poll_rx disconnected {:?}", err), } diff --git a/src/frontend/muxserver/mod.rs b/src/frontend/muxserver/mod.rs index c701064cf..af9b6cb4e 100644 --- a/src/frontend/muxserver/mod.rs +++ b/src/frontend/muxserver/mod.rs @@ -62,7 +62,7 @@ impl FrontEnd for MuxServerFrontEnd { fn run_forever(&self) -> Result<(), Error> { loop { match self.rx.recv() { - Ok(func) => func.call(), + Ok(func) => func(), Err(err) => bail!("while waiting for events: {:?}", err), } diff --git a/src/frontend/xwindows/x11loop.rs b/src/frontend/xwindows/x11loop.rs index f29c8a0f2..8a64a9a00 100644 --- a/src/frontend/xwindows/x11loop.rs +++ b/src/frontend/xwindows/x11loop.rs @@ -248,7 +248,7 @@ impl GuiEventLoop { fn process_gui_exec(&self) -> Result<(), Error> { match self.gui_rx.try_recv() { - Ok(func) => func.call(), + Ok(func) => func(), Err(TryRecvError::Empty) => return Ok(()), Err(err) => bail!("poll_rx disconnected {:?}", err), }