diff --git a/src/main.rs b/src/main.rs index 1fb6a6c8e29e6fcd12b1d327b4aae075492b346b..736a85235702737111d94131b6c94ac822f0c4cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,6 @@ use iron_cors::CorsMiddleware; use lazy_static::lazy_static; use mime_guess as mime_types; use multipart::server::{Multipart, SaveResult}; -use open; use path_dedot::ParseDot; use percent_encoding::percent_decode; use pretty_bytes::converter::convert; @@ -265,7 +264,7 @@ fn main() { match open::that(&host) { Ok(_) => println!("Openning {} in default browser", &host), - Err(err) => eprintln!("Unable to open in default browser {}", err.to_string()), + Err(err) => eprintln!("Unable to open in default browser {}", err), } } @@ -510,11 +509,7 @@ impl Handler for MainHandler { } impl MainHandler { - fn save_files( - &self, - req: &mut Request, - path: &PathBuf, - ) -> Result<(), (status::Status, String)> { + fn save_files(&self, req: &mut Request, path: &Path) -> Result<(), (status::Status, String)> { match Multipart::from_request(req) { Ok(mut multipart) => { // Fetching all data and processing it. @@ -566,7 +561,7 @@ impl MainHandler { for field in files_fields { let mut data = field.data.readable().unwrap(); let headers = &field.headers; - let mut target_path = path.clone(); + let mut target_path = path.to_owned(); target_path.push(headers.filename.clone().unwrap()); if let Err(errno) = std::fs::File::create(target_path) @@ -600,7 +595,7 @@ impl MainHandler { fn list_directory( &self, req: &mut Request, - fs_path: &PathBuf, + fs_path: &Path, path_prefix: &[String], ) -> IronResult<Response> { struct Entry { @@ -609,7 +604,7 @@ impl MainHandler { } let mut resp = Response::with(status::Ok); - let mut fs_path = fs_path.clone(); + let mut fs_path = fs_path.to_owned(); let mut rows = Vec::new(); let read_dir = fs::read_dir(&fs_path).map_err(error_io2iron)?; @@ -625,8 +620,7 @@ impl MainHandler { // Breadcrumb navigation let breadcrumb = if !path_prefix.is_empty() { let mut breadcrumb = path_prefix.to_owned(); - let mut bread_links: Vec<String> = Vec::new(); - bread_links.push(breadcrumb.pop().unwrap()); + let mut bread_links: Vec<String> = vec![breadcrumb.pop().unwrap()]; while !breadcrumb.is_empty() { bread_links.push(format!( r#"<a href="/{link}/"><strong>{label}</strong></a>"#, @@ -662,21 +656,13 @@ impl MainHandler { } if let Some(field) = sort_field { - if SORT_FIELDS - .iter() - .position(|s| *s == field.as_str()) - .is_none() - { + if !SORT_FIELDS.iter().any(|s| *s == field.as_str()) { return Err(IronError::new( StringError(format!("Unknown sort field: {}", field)), status::BadRequest, )); } - if vec![ORDER_ASC, ORDER_DESC] - .iter() - .position(|s| *s == order) - .is_none() - { + if ![ORDER_ASC, ORDER_DESC].iter().any(|s| *s == order) { return Err(IronError::new( StringError(format!("Unknown sort order: {}", order)), status::BadRequest, @@ -929,11 +915,7 @@ impl MainHandler { // [Reference]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match // Check header::If-Match if let Some(&IfMatch::Items(ref items)) = req.headers.get::<IfMatch>() { - if items - .iter() - .position(|item| item.strong_eq(&etag)) - .is_none() - { + if !items.iter().any(|item| item.strong_eq(&etag)) { return Err(IronError::new( StringError("Etag not matched".to_owned()), status::RangeNotSatisfiable,