Skip to content

Commit bb9fb69

Browse files
committed
Upgrade Rust edition, fix formatting and clippy issues
1 parent cac6156 commit bb9fb69

30 files changed

+287
-296
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ readme = "README.md"
55
description = "Rust WebDAV server library. A fork of the webdav-handler crate."
66
repository = "https://github.com/messense/dav-server-rs"
77
authors = ["Miquel van Smoorenburg <mike@langeraar.net>", "messense <messense@icloud.com>"]
8-
edition = "2018"
8+
edition = "2024"
99
license = "Apache-2.0"
1010
keywords = ["webdav"]
1111
categories = ["web-programming"]

examples/actix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::io;
22

3-
use actix_web::{web, App, HttpServer};
3+
use actix_web::{App, HttpServer, web};
44
use dav_server::actix::*;
5-
use dav_server::{fakels::FakeLs, localfs::LocalFs, DavConfig, DavHandler};
5+
use dav_server::{DavConfig, DavHandler, fakels::FakeLs, localfs::LocalFs};
66

77
pub async fn dav_handler(req: DavRequest, davhandler: web::Data<DavHandler>) -> DavResponse {
88
if let Some(prefix) = req.prefix() {

examples/auth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::{convert::Infallible, fmt::Display, net::SocketAddr, path::Path};
22

3-
use futures_util::{stream, StreamExt};
3+
use futures_util::{StreamExt, stream};
44
use http::{Request, Response, StatusCode};
55
use hyper::{body::Incoming, server::conn::http1, service::service_fn};
66
use hyper_util::rt::TokioIo;
77
use tokio::{net::TcpListener, task::spawn};
88

99
use dav_server::{
10+
DavHandler,
1011
body::Body,
1112
davpath::DavPath,
1213
fakels::FakeLs,
@@ -15,7 +16,6 @@ use dav_server::{
1516
OpenOptions, ReadDirMeta,
1617
},
1718
localfs::LocalFs,
18-
DavHandler,
1919
};
2020

2121
/// The server example demonstrates a limited scope policy for access to the file system.
@@ -129,7 +129,7 @@ enum Filter {
129129

130130
impl Filter {
131131
fn from_request(request: &Request<Incoming>) -> Result<Self, Box<dyn Display>> {
132-
use headers::{authorization::Basic, Authorization, HeaderMapExt};
132+
use headers::{Authorization, HeaderMapExt, authorization::Basic};
133133

134134
let auth = request
135135
.headers()

examples/hyper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use hyper::{server::conn::http1, service::service_fn};
44
use hyper_util::rt::TokioIo;
55
use tokio::net::TcpListener;
66

7-
use dav_server::{fakels::FakeLs, localfs::LocalFs, DavHandler};
7+
use dav_server::{DavHandler, fakels::FakeLs, localfs::LocalFs};
88

99
#[tokio::main]
1010
async fn main() {

examples/sample-litmus-server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
use std::{convert::Infallible, error::Error, net::SocketAddr};
99

1010
use clap::Parser;
11-
use headers::{authorization::Basic, Authorization, HeaderMapExt};
11+
use headers::{Authorization, HeaderMapExt, authorization::Basic};
1212
use hyper::{server::conn::http1, service::service_fn};
1313
use hyper_util::rt::TokioIo;
1414
use tokio::net::TcpListener;
1515

16-
use dav_server::{body::Body, fakels, localfs, memfs, memls, DavConfig, DavHandler};
16+
use dav_server::{DavConfig, DavHandler, body::Body, fakels, localfs, memfs, memls};
1717

1818
#[derive(Clone)]
1919
struct Server {

src/actix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use std::{
2121

2222
use actix_web::body::BoxBody;
2323
use actix_web::error::PayloadError;
24-
use actix_web::{dev, Error, FromRequest, HttpRequest, HttpResponse};
24+
use actix_web::{Error, FromRequest, HttpRequest, HttpResponse, dev};
2525
use bytes::Bytes;
26-
use futures_util::{future, Stream};
26+
use futures_util::{Stream, future};
2727
use pin_project::pin_project;
2828

2929
/// http::Request compatibility.

src/conditional.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ pub(crate) fn http_if_match(req: &Request, meta: Option<&dyn DavMetaData>) -> Op
5858
if let Some(r) = req.headers().typed_get::<davheaders::IfMatch>() {
5959
let etag = meta.and_then(ETag::from_meta);
6060
if !etaglist_match(&r.0, meta.is_some(), etag.as_ref()) {
61-
trace!("precondition fail: If-Match {:?}", r);
61+
trace!("precondition fail: If-Match {r:?}");
6262
return Some(StatusCode::PRECONDITION_FAILED);
6363
}
6464
} else if let Some(r) = req.headers().typed_get::<headers::IfUnmodifiedSince>() {
6565
match file_modified {
6666
None => return Some(StatusCode::PRECONDITION_FAILED),
6767
Some(file_modified) => {
6868
if round_time(file_modified) > round_time(r) {
69-
trace!("precondition fail: If-Unmodified-Since {:?}", r);
69+
trace!("precondition fail: If-Unmodified-Since {r:?}");
7070
return Some(StatusCode::PRECONDITION_FAILED);
7171
}
7272
}
@@ -76,22 +76,20 @@ pub(crate) fn http_if_match(req: &Request, meta: Option<&dyn DavMetaData>) -> Op
7676
if let Some(r) = req.headers().typed_get::<davheaders::IfNoneMatch>() {
7777
let etag = meta.and_then(ETag::from_meta);
7878
if etaglist_match(&r.0, meta.is_some(), etag.as_ref()) {
79-
trace!("precondition fail: If-None-Match {:?}", r);
79+
trace!("precondition fail: If-None-Match {r:?}");
8080
if req.method() == Method::GET || req.method() == Method::HEAD {
8181
return Some(StatusCode::NOT_MODIFIED);
8282
} else {
8383
return Some(StatusCode::PRECONDITION_FAILED);
8484
}
8585
}
86-
} else if let Some(r) = req.headers().typed_get::<headers::IfModifiedSince>() {
87-
if req.method() == Method::GET || req.method() == Method::HEAD {
88-
if let Some(file_modified) = file_modified {
89-
if round_time(file_modified) <= round_time(r) {
90-
trace!("not-modified If-Modified-Since {:?}", r);
91-
return Some(StatusCode::NOT_MODIFIED);
92-
}
93-
}
94-
}
86+
} else if let Some(r) = req.headers().typed_get::<headers::IfModifiedSince>()
87+
&& (req.method() == Method::GET || req.method() == Method::HEAD)
88+
&& let Some(file_modified) = file_modified
89+
&& round_time(file_modified) <= round_time(r)
90+
{
91+
trace!("not-modified If-Modified-Since {r:?}");
92+
return Some(StatusCode::NOT_MODIFIED);
9593
}
9694
None
9795
}

src/davhandler.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ use http_body_util::BodyExt;
1717
use crate::body::{Body, StreamBody};
1818
use crate::davheaders;
1919
use crate::davpath::DavPath;
20-
use crate::util::{dav_method, DavMethod, DavMethodSet};
20+
use crate::util::{DavMethod, DavMethodSet, dav_method};
2121

22+
use crate::DavResult;
2223
use crate::errors::DavError;
2324
use crate::fs::*;
2425
use crate::ls::*;
25-
use crate::voidfs::{is_voidfs, VoidFs};
26-
use crate::DavResult;
26+
use crate::voidfs::{VoidFs, is_voidfs};
2727

2828
/// WebDAV request handler.
2929
///
@@ -416,7 +416,7 @@ where
416416
resp
417417
}
418418
Err(err) => {
419-
debug!("== END REQUEST result {:?}", err);
419+
debug!("== END REQUEST result {err:?}");
420420
let mut resp = Response::builder();
421421
if is_ms && err.statuscode() == StatusCode::NOT_FOUND {
422422
// This is an attempt to convince Windows to not
@@ -459,10 +459,10 @@ where
459459
};
460460

461461
// debug when running the webdav litmus tests.
462-
if log_enabled!(log::Level::Debug) {
463-
if let Some(t) = req.headers().typed_get::<davheaders::XLitmus>() {
464-
debug!("X-Litmus: {:?}", t);
465-
}
462+
if log_enabled!(log::Level::Debug)
463+
&& let Some(t) = req.headers().typed_get::<davheaders::XLitmus>()
464+
{
465+
debug!("X-Litmus: {t:?}");
466466
}
467467

468468
// translate HTTP method to Webdav method.
@@ -497,15 +497,15 @@ where
497497
}
498498

499499
// see if method is allowed.
500-
if let Some(ref a) = self.allow {
501-
if !a.contains(method) {
502-
debug!(
503-
"method {} not allowed on request {}",
504-
req.method(),
505-
req.uri()
506-
);
507-
return Err(DavError::StatusClose(StatusCode::METHOD_NOT_ALLOWED));
508-
}
500+
if let Some(ref a) = self.allow
501+
&& !a.contains(method)
502+
{
503+
debug!(
504+
"method {} not allowed on request {}",
505+
req.method(),
506+
req.uri()
507+
);
508+
return Err(DavError::StatusClose(StatusCode::METHOD_NOT_ALLOWED));
509509
}
510510

511511
// make sure the request path is valid.
@@ -532,7 +532,7 @@ where
532532
}
533533
}
534534

535-
debug!("== START REQUEST {:?} {}", method, path);
535+
debug!("== START REQUEST {method:?} {path}");
536536

537537
match method {
538538
DavMethod::Options => self.handle_options(&req).await,

src/davheaders.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn map_invalid(_e: impl std::error::Error) -> headers::Error {
4848
}
4949

5050
macro_rules! header {
51-
($tname:ident, $hname:ident, $sname:expr) => {
51+
($tname:ident, $hname:ident, $sname:expr_2021) => {
5252
lazy_static! {
5353
pub static ref $hname: HeaderName = HeaderName::from_static($sname);
5454
}
@@ -226,7 +226,7 @@ impl Header for Timeout {
226226
}
227227
first = false;
228228
match *s {
229-
DavTimeout::Seconds(n) => value.push_str(&format!("Second-{}", n)),
229+
DavTimeout::Seconds(n) => value.push_str(&format!("Second-{n}")),
230230
DavTimeout::Infinite => value.push_str("Infinite"),
231231
}
232232
}
@@ -250,10 +250,10 @@ impl Header for Destination {
250250
if s.starts_with('/') {
251251
return Ok(Destination(s.to_string()));
252252
}
253-
if let Some(caps) = RE_URL.captures(s) {
254-
if let Some(path) = caps.get(1) {
255-
return Ok(Destination(path.as_str().to_string()));
256-
}
253+
if let Some(caps) = RE_URL.captures(s)
254+
&& let Some(path) = caps.get(1)
255+
{
256+
return Ok(Destination(path.as_str().to_string()));
257257
}
258258
Err(invalid())
259259
}
@@ -313,7 +313,7 @@ impl ETag {
313313
} else {
314314
let w = if weak { "W/" } else { "" };
315315
Ok(ETag {
316-
tag: format!("{}\"{}\"", w, t),
316+
tag: format!("{w}\"{t}\""),
317317
weak,
318318
})
319319
}
@@ -322,7 +322,7 @@ impl ETag {
322322
pub fn from_meta(meta: &dyn DavMetaData) -> Option<ETag> {
323323
let tag = meta.etag()?;
324324
Some(ETag {
325-
tag: format!("\"{}\"", tag),
325+
tag: format!("\"{tag}\""),
326326
weak: false,
327327
})
328328
}
@@ -587,9 +587,9 @@ impl Header for XUpdateRange {
587587
{
588588
let value = match *self {
589589
XUpdateRange::Append => "append".to_string(),
590-
XUpdateRange::FromTo(b, e) => format!("{}-{}", b, e),
591-
XUpdateRange::AllFrom(b) => format!("{}-", b),
592-
XUpdateRange::Last(e) => format!("-{}", e),
590+
XUpdateRange::FromTo(b, e) => format!("{b}-{e}"),
591+
XUpdateRange::AllFrom(b) => format!("{b}-"),
592+
XUpdateRange::Last(e) => format!("-{e}"),
593593
};
594594
values.extend(std::iter::once(HeaderValue::from_str(&value).unwrap()));
595595
}
@@ -654,10 +654,10 @@ enum IfState {
654654

655655
// helpers.
656656
fn is_whitespace(c: u8) -> bool {
657-
b" \t\r\n".iter().any(|&x| x == c)
657+
b" \t\r\n".contains(&c)
658658
}
659659
fn is_special(c: u8) -> bool {
660-
b"<>()[]".iter().any(|&x| x == c)
660+
b"<>()[]".contains(&c)
661661
}
662662

663663
fn trim_left(mut out: &'_ [u8]) -> &'_ [u8] {

src/davpath.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Error for ParseError {
6969

7070
impl std::fmt::Display for ParseError {
7171
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
72-
write!(f, "{:?}", self)
72+
write!(f, "{self:?}")
7373
}
7474
}
7575

@@ -422,12 +422,11 @@ impl DavPathRef {
422422
pub(crate) fn get_mime_type_str(&self) -> &'static str {
423423
let name = self.file_name_bytes();
424424
let d = name.rsplitn(2, |&c| c == b'.').collect::<Vec<&[u8]>>();
425-
if d.len() > 1 {
426-
if let Ok(ext) = std::str::from_utf8(d[0]) {
427-
if let Some(t) = mime_guess::from_ext(ext).first_raw() {
428-
return t;
429-
}
430-
}
425+
if d.len() > 1
426+
&& let Ok(ext) = std::str::from_utf8(d[0])
427+
&& let Some(t) = mime_guess::from_ext(ext).first_raw()
428+
{
429+
return t;
431430
}
432431
"application/octet-stream"
433432
}

0 commit comments

Comments
 (0)