Skip to content

Commit 3d01f90

Browse files
committed
Upgrade Rust edition, fix formatting and clippy issues
1 parent bd94216 commit 3d01f90

27 files changed

+228
-237
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: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,13 @@ pub(crate) fn http_if_match(req: &Request, meta: Option<&dyn DavMetaData>) -> Op
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: 16 additions & 16 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
///
@@ -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.

src/davheaders.rs

Lines changed: 5 additions & 5 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
}
@@ -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
}

src/davpath.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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)