Skip to content

Commit add79a7

Browse files
committed
fix clippy
1 parent 10328af commit add79a7

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

src/main.rs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use iron_cors::CorsMiddleware;
2323
use lazy_static::lazy_static;
2424
use mime_guess as mime_types;
2525
use multipart::server::{Multipart, SaveResult};
26-
use open;
2726
use path_dedot::ParseDot;
2827
use percent_encoding::percent_decode;
2928
use pretty_bytes::converter::convert;
@@ -265,7 +264,7 @@ fn main() {
265264

266265
match open::that(&host) {
267266
Ok(_) => println!("Openning {} in default browser", &host),
268-
Err(err) => eprintln!("Unable to open in default browser {}", err.to_string()),
267+
Err(err) => eprintln!("Unable to open in default browser {}", err),
269268
}
270269
}
271270

@@ -510,11 +509,7 @@ impl Handler for MainHandler {
510509
}
511510

512511
impl MainHandler {
513-
fn save_files(
514-
&self,
515-
req: &mut Request,
516-
path: &PathBuf,
517-
) -> Result<(), (status::Status, String)> {
512+
fn save_files(&self, req: &mut Request, path: &Path) -> Result<(), (status::Status, String)> {
518513
match Multipart::from_request(req) {
519514
Ok(mut multipart) => {
520515
// Fetching all data and processing it.
@@ -566,7 +561,7 @@ impl MainHandler {
566561
for field in files_fields {
567562
let mut data = field.data.readable().unwrap();
568563
let headers = &field.headers;
569-
let mut target_path = path.clone();
564+
let mut target_path = path.to_owned();
570565

571566
target_path.push(headers.filename.clone().unwrap());
572567
if let Err(errno) = std::fs::File::create(target_path)
@@ -600,7 +595,7 @@ impl MainHandler {
600595
fn list_directory(
601596
&self,
602597
req: &mut Request,
603-
fs_path: &PathBuf,
598+
fs_path: &Path,
604599
path_prefix: &[String],
605600
) -> IronResult<Response> {
606601
struct Entry {
@@ -609,7 +604,7 @@ impl MainHandler {
609604
}
610605

611606
let mut resp = Response::with(status::Ok);
612-
let mut fs_path = fs_path.clone();
607+
let mut fs_path = fs_path.to_owned();
613608
let mut rows = Vec::new();
614609

615610
let read_dir = fs::read_dir(&fs_path).map_err(error_io2iron)?;
@@ -625,8 +620,7 @@ impl MainHandler {
625620
// Breadcrumb navigation
626621
let breadcrumb = if !path_prefix.is_empty() {
627622
let mut breadcrumb = path_prefix.to_owned();
628-
let mut bread_links: Vec<String> = Vec::new();
629-
bread_links.push(breadcrumb.pop().unwrap());
623+
let mut bread_links: Vec<String> = vec![breadcrumb.pop().unwrap()];
630624
while !breadcrumb.is_empty() {
631625
bread_links.push(format!(
632626
r#"<a href="/{link}/"><strong>{label}</strong></a>"#,
@@ -662,21 +656,13 @@ impl MainHandler {
662656
}
663657

664658
if let Some(field) = sort_field {
665-
if SORT_FIELDS
666-
.iter()
667-
.position(|s| *s == field.as_str())
668-
.is_none()
669-
{
659+
if !SORT_FIELDS.iter().any(|s| *s == field.as_str()) {
670660
return Err(IronError::new(
671661
StringError(format!("Unknown sort field: {}", field)),
672662
status::BadRequest,
673663
));
674664
}
675-
if vec![ORDER_ASC, ORDER_DESC]
676-
.iter()
677-
.position(|s| *s == order)
678-
.is_none()
679-
{
665+
if ![ORDER_ASC, ORDER_DESC].iter().any(|s| *s == order) {
680666
return Err(IronError::new(
681667
StringError(format!("Unknown sort order: {}", order)),
682668
status::BadRequest,
@@ -929,11 +915,7 @@ impl MainHandler {
929915
// [Reference]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match
930916
// Check header::If-Match
931917
if let Some(&IfMatch::Items(ref items)) = req.headers.get::<IfMatch>() {
932-
if items
933-
.iter()
934-
.position(|item| item.strong_eq(&etag))
935-
.is_none()
936-
{
918+
if !items.iter().any(|item| item.strong_eq(&etag)) {
937919
return Err(IronError::new(
938920
StringError("Etag not matched".to_owned()),
939921
status::RangeNotSatisfiable,

0 commit comments

Comments
 (0)