init commit

This commit is contained in:
sigoden
2022-05-26 16:17:55 +08:00
commit 1c97c01096
8 changed files with 1310 additions and 0 deletions

27
src/main.rs Normal file
View File

@@ -0,0 +1,27 @@
macro_rules! bail {
($($tt:tt)*) => {
return Err(From::from(format!($($tt)*)))
}
}
mod args;
mod server;
pub type BoxResult<T> = Result<T, Box<dyn std::error::Error>>;
use crate::args::{matches, Args};
use crate::server::serve;
#[tokio::main]
async fn main() {
Args::parse(matches())
.map(serve)
.unwrap_or_else(handle_err)
.await
.unwrap_or_else(handle_err);
}
fn handle_err<T>(err: Box<dyn std::error::Error>) -> T {
eprintln!("Server error: {}", err);
std::process::exit(1);
}