From 47883376c1df79216142d5b75cde10445e7cc40e Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 19 Feb 2023 12:24:42 +0800 Subject: [PATCH] chore: fix cargo clippy (#174) --- src/auth.rs | 6 +++--- src/log_http.rs | 2 +- src/main.rs | 12 ++++++------ src/server.rs | 36 +++++++++++++++--------------------- src/tls.rs | 2 +- 5 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index e73b42b..5752fe9 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -43,7 +43,7 @@ impl AccessControl { } for rule in raw_rules { let parts: Vec<&str> = rule.split('@').collect(); - let create_err = || format!("Invalid auth `{}`", rule).into(); + let create_err = || format!("Invalid auth `{rule}`").into(); match parts.as_slice() { [path, readwrite] => { let control = PathControl { @@ -172,7 +172,7 @@ impl Account { let user = p[0]; let pass = p[1]; let mut h = Context::new(); - h.consume(format!("{}:{}:{}", user, REALM, pass).as_bytes()); + h.consume(format!("{user}:{REALM}:{pass}").as_bytes()); Some(Account { user: user.to_owned(), pass: format!("{:x}", h.compute()), @@ -190,7 +190,7 @@ impl AuthMethod { pub fn www_auth(&self, stale: bool) -> String { match self { AuthMethod::Basic => { - format!("Basic realm=\"{}\"", REALM) + format!("Basic realm=\"{REALM}\"") } AuthMethod::Digest => { let str_stale = if stale { "stale=true," } else { "" }; diff --git a/src/log_http.rs b/src/log_http.rs index 9f86fe4..9dc8acb 100644 --- a/src/log_http.rs +++ b/src/log_http.rs @@ -72,7 +72,7 @@ impl FromStr for LogHttp { let mut elements = vec![]; let mut is_var = false; let mut cache = String::new(); - for c in format!("{} ", s).chars() { + for c in format!("{s} ").chars() { if c == '$' { if !cache.is_empty() { elements.push(LogElement::Literal(cache.to_string())); diff --git a/src/main.rs b/src/main.rs index 5df3415..165acfb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ async fn main() { } async fn run() -> BoxResult<()> { - logger::init().map_err(|e| format!("Failed to init logger, {}", e))?; + logger::init().map_err(|e| format!("Failed to init logger, {e}"))?; let cmd = build_cli(); let matches = cmd.get_matches(); if let Some(generator) = matches.get_one::("completions") { @@ -92,7 +92,7 @@ fn serve( match bind_addr { BindAddr::Address(ip) => { let incoming = create_addr_incoming(SocketAddr::new(*ip, port)) - .map_err(|e| format!("Failed to bind `{}:{}`, {}", ip, port, e))?; + .map_err(|e| format!("Failed to bind `{ip}:{port}`, {e}"))?; match args.tls.as_ref() { #[cfg(feature = "tls")] Some((certs, key)) => { @@ -180,7 +180,7 @@ fn print_listening(args: Arc) -> BoxResult<()> { } if ipv4 || ipv6 { let ifaces = if_addrs::get_if_addrs() - .map_err(|e| format!("Failed to get local interface addresses: {}", e))?; + .map_err(|e| format!("Failed to get local interface addresses: {e}"))?; for iface in ifaces.into_iter() { let local_ip = iface.ip(); if ipv4 && local_ip.is_ipv4() { @@ -212,17 +212,17 @@ fn print_listening(args: Arc) -> BoxResult<()> { } else { let info = urls .iter() - .map(|v| format!(" {}", v)) + .map(|v| format!(" {v}")) .collect::>() .join("\n"); - println!("Listening on:\n{}\n", info); + println!("Listening on:\n{info}\n"); } Ok(()) } fn handle_err(err: Box) -> T { - eprintln!("error: {}", err); + eprintln!("error: {err}"); std::process::exit(1); } diff --git a/src/server.rs b/src/server.rs index eea71a8..7dae52c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -643,7 +643,7 @@ impl Server { res.headers_mut() .insert(CONTENT_RANGE, content_range.parse().unwrap()); res.headers_mut() - .insert(CONTENT_LENGTH, format!("{}", part_size).parse().unwrap()); + .insert(CONTENT_LENGTH, format!("{part_size}").parse().unwrap()); if head_only { return Ok(()); } @@ -651,11 +651,11 @@ impl Server { } else { *res.status_mut() = StatusCode::RANGE_NOT_SATISFIABLE; res.headers_mut() - .insert(CONTENT_RANGE, format!("bytes */{}", size).parse().unwrap()); + .insert(CONTENT_RANGE, format!("bytes */{size}").parse().unwrap()); } } else { res.headers_mut() - .insert(CONTENT_LENGTH, format!("{}", size).parse().unwrap()); + .insert(CONTENT_LENGTH, format!("{size}").parse().unwrap()); if head_only { return Ok(()); } @@ -767,15 +767,14 @@ impl Server { HeaderValue::from_static("application/xml; charset=utf-8"), ); res.headers_mut() - .insert("lock-token", format!("<{}>", token).parse().unwrap()); + .insert("lock-token", format!("<{token}>").parse().unwrap()); *res.body_mut() = Body::from(format!( r#" -{} -{} -"#, - token, req_path +{token} +{req_path} +"# )); Ok(()) } @@ -783,14 +782,13 @@ impl Server { async fn handle_proppatch(&self, req_path: &str, res: &mut Response) -> BoxResult<()> { let output = format!( r#" -{} +{req_path} HTTP/1.1 403 Forbidden -"#, - req_path +"# ); res_multistatus(res, &output); Ok(()) @@ -1021,17 +1019,16 @@ impl PathItem { match self.path_type { PathType::Dir | PathType::SymlinkDir => format!( r#" -{} +{href} -{} -{} +{displayname} +{mtime} HTTP/1.1 200 OK -"#, - href, displayname, mtime +"# ), PathType::File | PathType::SymlinkFile => format!( r#" @@ -1120,9 +1117,8 @@ fn res_multistatus(res: &mut Response, content: &str) { *res.body_mut() = Body::from(format!( r#" -{} +{content} "#, - content, )); } @@ -1183,9 +1179,7 @@ fn extract_cache_headers(meta: &Metadata) -> Option<(ETag, LastModified)> { let mtime = meta.modified().ok()?; let timestamp = to_timestamp(&mtime); let size = meta.len(); - let etag = format!(r#""{}-{}""#, timestamp, size) - .parse::() - .unwrap(); + let etag = format!(r#""{timestamp}-{size}""#).parse::().unwrap(); let last_modified = LastModified::from(mtime); Some((etag, last_modified)) } diff --git a/src/tls.rs b/src/tls.rs index df6a066..06de802 100644 --- a/src/tls.rs +++ b/src/tls.rs @@ -150,7 +150,7 @@ pub fn load_private_key>( // Load and return a single private key. let keys = rustls_pemfile::read_all(&mut reader) - .map_err(|e| format!("There was a problem with reading private key: {:?}", e))? + .map_err(|e| format!("There was a problem with reading private key: {e:?}"))? .into_iter() .find_map(|item| match item { rustls_pemfile::Item::RSAKey(key)