From 8fd0981e782d6a3aaf872270cdebf08c3307c49e Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sun, 3 Apr 2022 14:03:40 +0200 Subject: [PATCH] Remove useless unsafe code --- src/main.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6dcac7f..51d9e20 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,8 +57,6 @@ impl Args { } } -static mut ARGS: Option = None; - struct NewFile { path: PathBuf, bytes: Vec, @@ -219,8 +217,6 @@ async fn main() -> std::io::Result<()> { panic!("Specified files path does not exists!"); } - unsafe { ARGS = Some(args.clone()); } - HttpServer::new(move || { App::new() @@ -238,7 +234,8 @@ async fn main() -> std::io::Result<()> { .default_handler(fn_service(|req: ServiceRequest| async { let (req, _) = req.into_parts(); - if let Some(h) = unsafe { ARGS.as_ref().unwrap() }.default_handler_path().as_ref() { + let args: &web::Data = req.app_data().unwrap(); + if let Some(h) = args.default_handler_path() { let file = NamedFile::open_async(h).await?; let res = file.into_response(&req); Ok(ServiceResponse::new(req, res))