diff --git a/src/auth.rs b/src/auth.rs index fae91bf..0aaa8b5 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -297,15 +297,14 @@ impl AccessPerm { pub fn www_authenticate(res: &mut Response, args: &Args) -> Result<()> { if args.auth.use_hashed_password { - let basic = HeaderValue::from_str(&format!("Basic realm=\"{}\"", REALM))?; + let basic = HeaderValue::from_str(&format!("Basic realm=\"{REALM}\""))?; res.headers_mut().insert(WWW_AUTHENTICATE, basic); } else { let nonce = create_nonce()?; let digest = HeaderValue::from_str(&format!( - "Digest realm=\"{}\", nonce=\"{}\", qop=\"auth\"", - REALM, nonce + "Digest realm=\"{REALM}\", nonce=\"{nonce}\", qop=\"auth\"" ))?; - let basic = HeaderValue::from_str(&format!("Basic realm=\"{}\"", REALM))?; + let basic = HeaderValue::from_str(&format!("Basic realm=\"{REALM}\""))?; res.headers_mut().append(WWW_AUTHENTICATE, digest); res.headers_mut().append(WWW_AUTHENTICATE, basic); } @@ -367,7 +366,7 @@ pub fn check_auth( } let mut h = Context::new(); - h.consume(format!("{}:{}:{}", auth_user, REALM, auth_pass).as_bytes()); + h.consume(format!("{auth_user}:{REALM}:{auth_pass}").as_bytes()); let auth_pass = format!("{:x}", h.compute()); let mut ha = Context::new(); diff --git a/src/http_logger.rs b/src/http_logger.rs index 9d1d644..b296c67 100644 --- a/src/http_logger.rs +++ b/src/http_logger.rs @@ -64,8 +64,8 @@ impl HttpLogger { } } match err { - Some(err) => error!("{} {}", output, err), - None => info!("{}", output), + Some(err) => error!("{output} {err}"), + None => info!("{output}"), } } } diff --git a/src/main.rs b/src/main.rs index 7267ad9..6a7d160 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ async fn main() -> Result<()> { ret = join_all(handles) => { for r in ret { if let Err(e) = r { - error!("{}", e); + error!("{e}"); } } Ok(()) @@ -154,7 +154,7 @@ fn serve(args: Args, running: Arc) -> Result>> { path.into() }; let listener = tokio::net::UnixListener::bind(socket_path) - .with_context(|| format!("Failed to bind `{}`", path))?; + .with_context(|| format!("Failed to bind `{path}`"))?; let handle = tokio::spawn(async move { loop { let Ok((stream, _addr)) = listener.accept().await else { diff --git a/src/server.rs b/src/server.rs index e78f0d5..c7165cd 100644 --- a/src/server.rs +++ b/src/server.rs @@ -502,7 +502,7 @@ impl Server { }; let stream = IncomingStream::new(req.into_body()); - let body_with_io_error = stream.map_err(|err| io::Error::new(io::ErrorKind::Other, err)); + let body_with_io_error = stream.map_err(io::Error::other); let body_reader = StreamReader::new(body_with_io_error); pin_mut!(body_reader); @@ -628,7 +628,7 @@ impl Server { ) -> Result<()> { let (mut writer, reader) = tokio::io::duplex(BUF_SIZE); let filename = try_get_file_name(path)?; - set_content_disposition(res, false, &format!("{}.zip", filename))?; + set_content_disposition(res, false, &format!("{filename}.zip"))?; res.headers_mut() .insert("content-type", HeaderValue::from_static("application/zip")); if head_only { @@ -855,7 +855,7 @@ impl Server { file.seek(SeekFrom::Start(start)).await?; let range_size = end - start + 1; *res.status_mut() = StatusCode::PARTIAL_CONTENT; - let content_range = format!("bytes {}-{}/{}", start, end, size); + let content_range = format!("bytes {start}-{end}/{size}"); res.headers_mut() .insert(CONTENT_RANGE, content_range.parse()?); res.headers_mut() @@ -879,7 +879,7 @@ impl Server { for (start, end) in ranges { file.seek(SeekFrom::Start(start)).await?; let range_size = end - start + 1; - let content_range = format!("bytes {}-{}/{}", start, end, size); + let content_range = format!("bytes {start}-{end}/{size}"); let part_header = format!( "--{boundary}\r\nContent-Type: {content_type}\r\nContent-Range: {content_range}\r\n\r\n", ); @@ -1704,7 +1704,7 @@ fn set_content_disposition(res: &mut Response, inline: bool, filename: &str) -> }) .collect(); let value = if filename.is_ascii() { - HeaderValue::from_str(&format!("{kind}; filename=\"{}\"", filename,))? + HeaderValue::from_str(&format!("{kind}; filename=\"{filename}\"",))? } else { HeaderValue::from_str(&format!( "{kind}; filename=\"{}\"; filename*=UTF-8''{}", @@ -1799,7 +1799,7 @@ async fn sha256_file(path: &Path) -> Result { } let result = hasher.finalize(); - Ok(format!("{:x}", result)) + Ok(format!("{result:x}")) } fn has_query_flag(query_params: &HashMap, name: &str) -> bool { diff --git a/tests/cache.rs b/tests/cache.rs index 5890d81..2e4af2f 100644 --- a/tests/cache.rs +++ b/tests/cache.rs @@ -49,7 +49,7 @@ fn same_etag(etag: &str) -> String { } fn different_etag(etag: &str) -> String { - format!("{}1234", etag) + format!("{etag}1234") } #[rstest] diff --git a/tests/range.rs b/tests/range.rs index cb56889..209ed1e 100644 --- a/tests/range.rs +++ b/tests/range.rs @@ -41,7 +41,7 @@ fn get_file_range_invalid(server: TestServer) -> Result<(), Error> { } fn parse_multipart_body<'a>(body: &'a str, boundary: &str) -> Vec<(HeaderMap, &'a str)> { - body.split(&format!("--{}", boundary)) + body.split(&format!("--{boundary}")) .filter(|part| !part.is_empty() && *part != "--\r\n") .map(|part| { let (head, body) = part.trim_ascii().split_once("\r\n\r\n").unwrap();