1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

remove boxfnonce: now require rust 1.35+

Rust can now naturally deal with with these constructs, so drop the
external crate.
This commit is contained in:
Wez Furlong 2019-05-26 09:14:20 -07:00
parent 3cf20acd13
commit e1a1530d22
6 changed files with 27 additions and 30 deletions

View File

@ -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"

View File

@ -6,5 +6,4 @@ edition = "2018"
[dependencies]
failure = "0.1"
boxfnonce = "0.1"
rayon = "1.0"

View File

@ -1,9 +1,8 @@
use boxfnonce::SendBoxFnOnce;
use failure::Error;
use failure::{Error, Fallible};
use std::sync::{Arc, Condvar, Mutex};
type NextFunc<T> = SendBoxFnOnce<'static, (Result<T, Error>,)>;
pub type SpawnFunc = SendBoxFnOnce<'static, ()>;
type NextFunc<T> = Box<dyn FnOnce(Fallible<T>) + Send>;
pub type SpawnFunc = Box<dyn FnOnce() + Send>;
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<Executor> {
Box::new(RayonExecutor::new())
@ -103,7 +102,7 @@ impl<T> Promise<T> {
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<T: Send + 'static> Future<T> {
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<T: Send + 'static> Future<T> {
fn chain(self, f: NextFunc<T>) {
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<T: Send + 'static> Future<T> {
{
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<T: Send + 'static> Future<T> {
{
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<T: Send + 'static> Future<T> {
{
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);
}));

View File

@ -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),
}

View File

@ -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),
}

View File

@ -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),
}