From 713a7d4741558b5a8fdf43e09b0c3ddecb92b058 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Sat, 20 Oct 2018 22:06:42 -0400 Subject: [PATCH] Be less "clever" in main.rs, don't twist everything into the runtime. --- src/main.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 636896f..e252548 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,28 +35,26 @@ fn options() -> App<'static, 'static> { fn main() { let args = options().get_matches(); - tokio_run(match args.subcommand() { - ("filter", Some(sub_args)) => box_up(filter::run(sub_args)), - ("relay", Some(sub_args)) => box_up(relay::run(sub_args)), - ("send", Some(sub_args)) => box_up(send::run(sub_args)), - ("dump", Some(sub_args)) => box_up(dump::run(sub_args)), - _ => box_up(futures::lazy(|| { + match args.subcommand() { + ("filter", Some(sub_args)) => { tokio_run(filter::run(sub_args)); }, + ("relay", Some(sub_args)) => { relay::run(sub_args).unwrap_or_else(handle_error); }, + ("send", Some(sub_args)) => { tokio_run(send::run(sub_args)); }, + ("dump", Some(sub_args)) => { dump::run(sub_args).unwrap_or_else(handle_error); }, + _ => { options().print_help().unwrap(); println!(""); - Ok(()) - })) - }); + } + }; } -fn tokio_run(task: Box + Send>) { +fn handle_error(err: WebmetroError) { + eprintln!("Error: {}", err); +} + +fn tokio_run + Send>(task: T) +where T::Future: Send + 'static { rt::run(task.into_future().map_err(|err| { - eprintln!("Error: {}", err); + handle_error(err); ::std::process::exit(1); })); } - -fn box_up>(task: F) -> Box + Send> -where F::Future: Send + 'static -{ - Box::new(task.into_future()) -}