From d9f92048b22fa909607288b34bccbe1a8c407401 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Sat, 4 Feb 2023 16:38:20 -0500 Subject: [PATCH] refactor: minor clippy syntax & format improvements --- src/control_headers.rs | 6 +++--- src/directory_listing.rs | 12 +++++------- src/server.rs | 4 ++-- src/settings/file.rs | 5 +---- src/settings/mod.rs | 2 +- src/tls.rs | 2 +- tests/dir_listing.rs | 4 ++-- tests/static_files.rs | 28 ++++++---------------------- 8 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/control_headers.rs b/src/control_headers.rs index 2512790..cdd6a4b 100644 --- a/src/control_headers.rs +++ b/src/control_headers.rs @@ -65,7 +65,7 @@ mod tests { assert_eq!(resp.status(), StatusCode::OK); assert_eq!( cache_control.to_str().unwrap(), - format!("public, max-age={}", MAX_AGE_ONE_HOUR) + format!("public, max-age={MAX_AGE_ONE_HOUR}") ); } } @@ -81,7 +81,7 @@ mod tests { assert_eq!(resp.status(), StatusCode::OK); assert_eq!( cache_control.to_str().unwrap(), - format!("public, max-age={}", MAX_AGE_ONE_DAY) + format!("public, max-age={MAX_AGE_ONE_DAY}") ); } @@ -97,7 +97,7 @@ mod tests { assert_eq!(resp.status(), StatusCode::OK); assert_eq!( cache_control.to_str().unwrap(), - format!("public, max-age={}", MAX_AGE_ONE_YEAR) + format!("public, max-age={MAX_AGE_ONE_YEAR}") ); } } diff --git a/src/directory_listing.rs b/src/directory_listing.rs index c251cbe..0bd0a7b 100644 --- a/src/directory_listing.rs +++ b/src/directory_listing.rs @@ -285,7 +285,7 @@ fn json_auto_index(entries: &mut [FileEntry], order_code: u8) -> Result json.push('{'); json.push_str(format!("\"name\":{},", json_quote_str(file_name.as_str())).as_str()); - json.push_str(format!("\"type\":\"{}\",", file_type).as_str()); + json.push_str(format!("\"type\":\"{file_type}\",").as_str()); let file_modified_str = file_modified.map_or("".to_owned(), |local_dt| { local_dt @@ -293,10 +293,10 @@ fn json_auto_index(entries: &mut [FileEntry], order_code: u8) -> Result .format(DATETIME_FORMAT_UTC) .to_string() }); - json.push_str(format!("\"mtime\":\"{}\"", file_modified_str).as_str()); + json.push_str(format!("\"mtime\":\"{file_modified_str}\"").as_str()); if !is_empty { - json.push_str(format!(",\"size\":{}", file_size).as_str()); + json.push_str(format!(",\"size\":{file_size}").as_str()); } json.push_str("},"); } @@ -372,8 +372,7 @@ fn html_auto_index<'a>( }); table_row = format!( - "{}{}{}{}", - table_row, file_uri, file_name_decoded, file_modified_str, filesize + "{table_row}{file_name_decoded}{file_modified_str}{filesize}" ); } @@ -389,8 +388,7 @@ fn html_auto_index<'a>( ); let html_page = format!( - "Index of {}{}

Index of {}

{}
{}{}

{}", - current_path, STYLE, current_path, summary, table_header, table_row, FOOTER + "Index of {current_path}{STYLE}

Index of {current_path}

{summary}
{table_header}{table_row}

{FOOTER}" ); Ok(html_page) diff --git a/src/server.rs b/src/server.rs index 0ff4d52..418e7db 100644 --- a/src/server.rs +++ b/src/server.rs @@ -93,7 +93,7 @@ impl Server { let (tcp_listener, addr_str); match general.fd { Some(fd) => { - addr_str = format!("@FD({})", fd); + addr_str = format!("@FD({fd})"); tcp_listener = ListenFd::from_env() .take_tcp_listener(fd)? .with_context(|| "failed to convert inherited 'fd' into a 'tcp' listener")?; @@ -109,7 +109,7 @@ impl Server { .with_context(|| format!("failed to parse {} address", general.host))?; let addr = SocketAddr::from((ip, general.port)); tcp_listener = TcpListener::bind(addr) - .with_context(|| format!("failed to bind to {} address", addr))?; + .with_context(|| format!("failed to bind to {addr} address"))?; addr_str = addr.to_string(); tracing::info!("server bound to tcp socket {}", addr_str); } diff --git a/src/settings/file.rs b/src/settings/file.rs index 1418e8f..35b060f 100644 --- a/src/settings/file.rs +++ b/src/settings/file.rs @@ -171,10 +171,7 @@ impl Settings { .with_context(|| "error during toml configuration file deserialization")?; for key in unused { - println!( - "Warning: unused configuration manifest key \"{}\" or unsupported", - key - ); + println!("Warning: unused configuration manifest key \"{key}\" or unsupported"); } Ok(manifest) diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 9dbf386..47483e1 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -277,7 +277,7 @@ impl Settings { source, destination: redirects_entry.destination.to_owned(), kind: StatusCode::from_u16(status_code).with_context(|| { - format!("invalid redirect status code: {}", status_code) + format!("invalid redirect status code: {status_code}") })?, }); } diff --git a/src/tls.rs b/src/tls.rs index 96cea6b..aaebec9 100644 --- a/src/tls.rs +++ b/src/tls.rs @@ -44,7 +44,7 @@ impl std::fmt::Display for TlsConfigError { TlsConfigError::Pkcs8ParseError => write!(f, "pkcs8 parse error"), TlsConfigError::RsaParseError => write!(f, "rsa parse error"), TlsConfigError::EmptyKey => write!(f, "key contains no private key"), - TlsConfigError::InvalidKey(err) => write!(f, "key contains an invalid key, {}", err), + TlsConfigError::InvalidKey(err) => write!(f, "key contains an invalid key, {err}"), } } } diff --git a/tests/dir_listing.rs b/tests/dir_listing.rs index 01ad20e..05e7007 100644 --- a/tests/dir_listing.rs +++ b/tests/dir_listing.rs @@ -258,13 +258,13 @@ mod tests { let first_entry = entries.first().unwrap(); assert_eq!(first_entry.name, "spécial directöry"); assert_eq!(first_entry.typed, "directory"); - assert_eq!(first_entry.mtime.is_empty(), false); + assert!(!first_entry.mtime.is_empty()); assert!(first_entry.size.is_none()); let last_entry = entries.last().unwrap(); assert_eq!(last_entry.name, "index.html.gz"); assert_eq!(last_entry.typed, "file"); - assert_eq!(last_entry.mtime.is_empty(), false); + assert!(!last_entry.mtime.is_empty()); assert!(last_entry.size.unwrap() > 300); } else { assert!(body_str.is_empty()); diff --git a/tests/static_files.rs b/tests/static_files.rs index dffe3a3..f54b9d5 100644 --- a/tests/static_files.rs +++ b/tests/static_files.rs @@ -50,11 +50,7 @@ mod tests { let ctype = &res.headers()["content-type"]; - assert!( - ctype == "text/html", - "content-type is not html: {:?}", - ctype, - ); + assert!(ctype == "text/html", "content-type is not html: {ctype:?}",); let body = hyper::body::to_bytes(res.body_mut()) .await @@ -92,11 +88,7 @@ mod tests { let ctype = &res.headers()["content-type"]; - assert!( - ctype == "text/html", - "content-type is not html: {:?}", - ctype, - ); + assert!(ctype == "text/html", "content-type is not html: {ctype:?}",); let body = hyper::body::to_bytes(res.body_mut()) .await @@ -183,7 +175,7 @@ mod tests { assert_eq!(res.headers()["location"], "assets/"); } Err(status) => { - panic!("expected a status 308 but not a status {}", status) + panic!("expected a status 308 but not a status {status}") } } } @@ -209,7 +201,7 @@ mod tests { assert_eq!(res.status(), 200); } Err(status) => { - panic!("expected a status 200 but not a status {}", status) + panic!("expected a status 200 but not a status {status}") } } } @@ -564,11 +556,7 @@ mod tests { let ctype = &res.headers()["content-type"]; - assert!( - ctype == "text/html", - "content-type is not html: {:?}", - ctype, - ); + assert!(ctype == "text/html", "content-type is not html: {ctype:?}",); let body = hyper::body::to_bytes(res.body_mut()) .await @@ -637,11 +625,7 @@ mod tests { let ctype = &res.headers()["content-type"]; - assert!( - ctype == "text/html", - "content-type is not html: {:?}", - ctype, - ); + assert!(ctype == "text/html", "content-type is not html: {ctype:?}",); } Err(_) => { panic!("unexpected status error") -- libgit2 1.7.2