Skip to content
Snippets Groups Projects
Commit add79a72 authored by Linfeng Qian's avatar Linfeng Qian
Browse files

fix clippy

parent 10328afe
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,6 @@ use iron_cors::CorsMiddleware; ...@@ -23,7 +23,6 @@ use iron_cors::CorsMiddleware;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use mime_guess as mime_types; use mime_guess as mime_types;
use multipart::server::{Multipart, SaveResult}; use multipart::server::{Multipart, SaveResult};
use open;
use path_dedot::ParseDot; use path_dedot::ParseDot;
use percent_encoding::percent_decode; use percent_encoding::percent_decode;
use pretty_bytes::converter::convert; use pretty_bytes::converter::convert;
...@@ -265,7 +264,7 @@ fn main() { ...@@ -265,7 +264,7 @@ fn main() {
match open::that(&host) { match open::that(&host) {
Ok(_) => println!("Openning {} in default browser", &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 { ...@@ -510,11 +509,7 @@ impl Handler for MainHandler {
} }
impl MainHandler { impl MainHandler {
fn save_files( fn save_files(&self, req: &mut Request, path: &Path) -> Result<(), (status::Status, String)> {
&self,
req: &mut Request,
path: &PathBuf,
) -> Result<(), (status::Status, String)> {
match Multipart::from_request(req) { match Multipart::from_request(req) {
Ok(mut multipart) => { Ok(mut multipart) => {
// Fetching all data and processing it. // Fetching all data and processing it.
...@@ -566,7 +561,7 @@ impl MainHandler { ...@@ -566,7 +561,7 @@ impl MainHandler {
for field in files_fields { for field in files_fields {
let mut data = field.data.readable().unwrap(); let mut data = field.data.readable().unwrap();
let headers = &field.headers; let headers = &field.headers;
let mut target_path = path.clone(); let mut target_path = path.to_owned();
target_path.push(headers.filename.clone().unwrap()); target_path.push(headers.filename.clone().unwrap());
if let Err(errno) = std::fs::File::create(target_path) if let Err(errno) = std::fs::File::create(target_path)
...@@ -600,7 +595,7 @@ impl MainHandler { ...@@ -600,7 +595,7 @@ impl MainHandler {
fn list_directory( fn list_directory(
&self, &self,
req: &mut Request, req: &mut Request,
fs_path: &PathBuf, fs_path: &Path,
path_prefix: &[String], path_prefix: &[String],
) -> IronResult<Response> { ) -> IronResult<Response> {
struct Entry { struct Entry {
...@@ -609,7 +604,7 @@ impl MainHandler { ...@@ -609,7 +604,7 @@ impl MainHandler {
} }
let mut resp = Response::with(status::Ok); 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 mut rows = Vec::new();
let read_dir = fs::read_dir(&fs_path).map_err(error_io2iron)?; let read_dir = fs::read_dir(&fs_path).map_err(error_io2iron)?;
...@@ -625,8 +620,7 @@ impl MainHandler { ...@@ -625,8 +620,7 @@ impl MainHandler {
// Breadcrumb navigation // Breadcrumb navigation
let breadcrumb = if !path_prefix.is_empty() { let breadcrumb = if !path_prefix.is_empty() {
let mut breadcrumb = path_prefix.to_owned(); let mut breadcrumb = path_prefix.to_owned();
let mut bread_links: Vec<String> = Vec::new(); let mut bread_links: Vec<String> = vec![breadcrumb.pop().unwrap()];
bread_links.push(breadcrumb.pop().unwrap());
while !breadcrumb.is_empty() { while !breadcrumb.is_empty() {
bread_links.push(format!( bread_links.push(format!(
r#"<a href="/{link}/"><strong>{label}</strong></a>"#, r#"<a href="/{link}/"><strong>{label}</strong></a>"#,
...@@ -662,21 +656,13 @@ impl MainHandler { ...@@ -662,21 +656,13 @@ impl MainHandler {
} }
if let Some(field) = sort_field { if let Some(field) = sort_field {
if SORT_FIELDS if !SORT_FIELDS.iter().any(|s| *s == field.as_str()) {
.iter()
.position(|s| *s == field.as_str())
.is_none()
{
return Err(IronError::new( return Err(IronError::new(
StringError(format!("Unknown sort field: {}", field)), StringError(format!("Unknown sort field: {}", field)),
status::BadRequest, status::BadRequest,
)); ));
} }
if vec![ORDER_ASC, ORDER_DESC] if ![ORDER_ASC, ORDER_DESC].iter().any(|s| *s == order) {
.iter()
.position(|s| *s == order)
.is_none()
{
return Err(IronError::new( return Err(IronError::new(
StringError(format!("Unknown sort order: {}", order)), StringError(format!("Unknown sort order: {}", order)),
status::BadRequest, status::BadRequest,
...@@ -929,11 +915,7 @@ impl MainHandler { ...@@ -929,11 +915,7 @@ impl MainHandler {
// [Reference]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match // [Reference]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match
// Check header::If-Match // Check header::If-Match
if let Some(&IfMatch::Items(ref items)) = req.headers.get::<IfMatch>() { if let Some(&IfMatch::Items(ref items)) = req.headers.get::<IfMatch>() {
if items if !items.iter().any(|item| item.strong_eq(&etag)) {
.iter()
.position(|item| item.strong_eq(&etag))
.is_none()
{
return Err(IronError::new( return Err(IronError::new(
StringError("Etag not matched".to_owned()), StringError("Etag not matched".to_owned()),
status::RangeNotSatisfiable, status::RangeNotSatisfiable,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment