chore: fix cargo clippy (#174)

This commit is contained in:
sigoden 2023-02-19 12:24:42 +08:00 committed by GitHub
parent fea9bf988a
commit 47883376c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 32 deletions

View file

@ -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 { "" };

View file

@ -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()));

View file

@ -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::<Shell>("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<Args>) -> 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<Args>) -> BoxResult<()> {
} else {
let info = urls
.iter()
.map(|v| format!(" {}", v))
.map(|v| format!(" {v}"))
.collect::<Vec<String>>()
.join("\n");
println!("Listening on:\n{}\n", info);
println!("Listening on:\n{info}\n");
}
Ok(())
}
fn handle_err<T>(err: Box<dyn std::error::Error>) -> T {
eprintln!("error: {}", err);
eprintln!("error: {err}");
std::process::exit(1);
}

View file

@ -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#"<?xml version="1.0" encoding="utf-8"?>
<D:prop xmlns:D="DAV:"><D:lockdiscovery><D:activelock>
<D:locktoken><D:href>{}</D:href></D:locktoken>
<D:lockroot><D:href>{}</D:href></D:lockroot>
</D:activelock></D:lockdiscovery></D:prop>"#,
token, req_path
<D:locktoken><D:href>{token}</D:href></D:locktoken>
<D:lockroot><D:href>{req_path}</D:href></D:lockroot>
</D:activelock></D:lockdiscovery></D:prop>"#
));
Ok(())
}
@ -783,14 +782,13 @@ impl Server {
async fn handle_proppatch(&self, req_path: &str, res: &mut Response) -> BoxResult<()> {
let output = format!(
r#"<D:response>
<D:href>{}</D:href>
<D:href>{req_path}</D:href>
<D:propstat>
<D:prop>
</D:prop>
<D:status>HTTP/1.1 403 Forbidden</D:status>
</D:propstat>
</D:response>"#,
req_path
</D:response>"#
);
res_multistatus(res, &output);
Ok(())
@ -1021,17 +1019,16 @@ impl PathItem {
match self.path_type {
PathType::Dir | PathType::SymlinkDir => format!(
r#"<D:response>
<D:href>{}</D:href>
<D:href>{href}</D:href>
<D:propstat>
<D:prop>
<D:displayname>{}</D:displayname>
<D:getlastmodified>{}</D:getlastmodified>
<D:displayname>{displayname}</D:displayname>
<D:getlastmodified>{mtime}</D:getlastmodified>
<D:resourcetype><D:collection/></D:resourcetype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>"#,
href, displayname, mtime
</D:response>"#
),
PathType::File | PathType::SymlinkFile => format!(
r#"<D:response>
@ -1120,9 +1117,8 @@ fn res_multistatus(res: &mut Response, content: &str) {
*res.body_mut() = Body::from(format!(
r#"<?xml version="1.0" encoding="utf-8" ?>
<D:multistatus xmlns:D="DAV:">
{}
{content}
</D:multistatus>"#,
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::<ETag>()
.unwrap();
let etag = format!(r#""{timestamp}-{size}""#).parse::<ETag>().unwrap();
let last_modified = LastModified::from(mtime);
Some((etag, last_modified))
}

View file

@ -150,7 +150,7 @@ pub fn load_private_key<T: AsRef<Path>>(
// 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)