refactor: minor clippy syntax & format improvements
Diff
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(-)
@@ -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}")
);
}
}
@@ -285,7 +285,7 @@ fn json_auto_index(entries: &mut [FileEntry], order_code: u8) -> Result<String>
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<String>
.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!(
"{}<tr><td><a href=\"{}\">{}</a></td><td>{}</td><td align=\"right\">{}</td></tr>",
table_row, file_uri, file_name_decoded, file_modified_str, filesize
"{table_row}<tr><td><a href=\"{file_uri}\">{file_name_decoded}</a></td><td>{file_modified_str}</td><td align=\"right\">{filesize}</td></tr>"
);
}
@@ -389,8 +388,7 @@ fn html_auto_index<'a>(
);
let html_page = format!(
"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>Index of {}</title>{}</head><body><h1>Index of {}</h1>{}<hr><table>{}{}</table><hr>{}</body></html>",
current_path, STYLE, current_path, summary, table_header, table_row, FOOTER
"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>Index of {current_path}</title>{STYLE}</head><body><h1>Index of {current_path}</h1>{summary}<hr><table>{table_header}{table_row}</table><hr>{FOOTER}</body></html>"
);
Ok(html_page)
@@ -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);
}
@@ -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)
@@ -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}")
})?,
});
}
@@ -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}"),
}
}
}
@@ -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());
@@ -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")