From 63832cca5745077fe43101f0d39b3b9fe02c111a Mon Sep 17 00:00:00 2001 From: eastfisher Date: Tue, 23 Aug 2022 14:22:08 +0800 Subject: [PATCH 1/4] add clippy hints --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b64efce0d075..505cf389c45b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,6 +104,8 @@ // Make sure all our public APIs have docs. #![warn(missing_docs)] +// Allowing/denying lints +#![deny(unused_qualifications)] // Private module with public types, they will be accessed via `opendal::Xxxx` mod accessor; From c34ff9f7f29db73c607438b70ab3c2f8f04bacc7 Mon Sep 17 00:00:00 2001 From: eastfisher Date: Tue, 23 Aug 2022 14:32:36 +0800 Subject: [PATCH 2/4] remove all unused qualifications --- src/http_util/header.rs | 8 ++++---- src/io_util/into_sink.rs | 4 ++-- src/io_util/into_stream.rs | 2 +- src/io_util/seekable_reader.rs | 4 ++-- src/services/azblob/backend.rs | 21 +++++++++------------ src/services/gcs/backend.rs | 8 ++++---- src/services/http/backend.rs | 15 ++++++--------- src/services/memory/backend.rs | 4 ++-- src/services/s3/backend.rs | 32 +++++++++++++------------------- 9 files changed, 43 insertions(+), 55 deletions(-) diff --git a/src/http_util/header.rs b/src/http_util/header.rs index 1eaad9498193..fb481e9ccd84 100644 --- a/src/http_util/header.rs +++ b/src/http_util/header.rs @@ -28,9 +28,9 @@ pub fn parse_content_length(headers: &HeaderMap) -> Result> { None => Ok(None), Some(v) => Ok(Some( v.to_str() - .map_err(|e| anyhow!("parse {} header: {:?}", http::header::CONTENT_LENGTH, e))? + .map_err(|e| anyhow!("parse {} header: {:?}", CONTENT_LENGTH, e))? .parse::() - .map_err(|e| anyhow!("parse {} header: {:?}", http::header::CONTENT_LENGTH, e))?, + .map_err(|e| anyhow!("parse {} header: {:?}", CONTENT_LENGTH, e))?, )), } } @@ -55,9 +55,9 @@ pub fn parse_last_modified(headers: &HeaderMap) -> Result Some(v) => { let v = v .to_str() - .map_err(|e| anyhow!("parse {} header: {:?}", http::header::LAST_MODIFIED, e))?; + .map_err(|e| anyhow!("parse {} header: {:?}", LAST_MODIFIED, e))?; let t = OffsetDateTime::parse(v, &Rfc2822) - .map_err(|e| anyhow!("parse {} header: {:?}", http::header::LAST_MODIFIED, e))?; + .map_err(|e| anyhow!("parse {} header: {:?}", LAST_MODIFIED, e))?; Ok(Some(t)) } diff --git a/src/io_util/into_sink.rs b/src/io_util/into_sink.rs index 4e1bfd224b23..18743409a049 100644 --- a/src/io_util/into_sink.rs +++ b/src/io_util/into_sink.rs @@ -51,7 +51,7 @@ use crate::BytesWrite; pub fn into_sink(w: W) -> IntoSink { IntoSink { w, - buf: bytes::Bytes::new(), + buf: Bytes::new(), } } @@ -59,7 +59,7 @@ pub fn into_sink(w: W) -> IntoSink { pub struct IntoSink { #[pin] w: W, - buf: bytes::Bytes, + buf: Bytes, } impl IntoSink diff --git a/src/io_util/into_stream.rs b/src/io_util/into_stream.rs index 7389fb3d9130..8b6168d71f0f 100644 --- a/src/io_util/into_stream.rs +++ b/src/io_util/into_stream.rs @@ -62,7 +62,7 @@ pub struct IntoStream { #[pin] r: R, cap: usize, - buf: bytes::BytesMut, + buf: BytesMut, } impl Stream for IntoStream diff --git a/src/io_util/seekable_reader.rs b/src/io_util/seekable_reader.rs index 18795c8a7fc6..29079b5feee1 100644 --- a/src/io_util/seekable_reader.rs +++ b/src/io_util/seekable_reader.rs @@ -104,7 +104,7 @@ impl AsyncRead for SeekableReader { mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], - ) -> Poll> { + ) -> Poll> { match &mut self.state { State::Idle => { let acc = self.acc.clone(); @@ -143,7 +143,7 @@ impl AsyncSeek for SeekableReader { mut self: Pin<&mut Self>, cx: &mut Context<'_>, pos: SeekFrom, - ) -> Poll> { + ) -> Poll> { if let State::Seeking(future) = &mut self.state { let meta = ready!(Pin::new(future).poll(cx))?; self.size = Some(meta.content_length() - self.offset.unwrap_or_default()) diff --git a/src/services/azblob/backend.rs b/src/services/azblob/backend.rs index 8c2185f3f652..7696f46feb6e 100644 --- a/src/services/azblob/backend.rs +++ b/src/services/azblob/backend.rs @@ -390,7 +390,7 @@ impl Accessor for Backend { let resp = self.get_blob_properties(&p).await?; match resp.status() { - http::StatusCode::OK => { + StatusCode::OK => { let mut m = ObjectMetadata::default(); if let Some(v) = parse_content_length(resp.headers()) @@ -461,7 +461,7 @@ impl Backend { path: &str, offset: Option, size: Option, - ) -> Result> { + ) -> Result> { let url = format!( "{}/{}/{}", self.endpoint, @@ -479,7 +479,7 @@ impl Backend { } let mut req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("read", path, e))?; self.signer @@ -523,7 +523,7 @@ impl Backend { pub(crate) async fn get_blob_properties( &self, path: &str, - ) -> Result> { + ) -> Result> { let url = format!( "{}/{}/{}", self.endpoint, @@ -534,7 +534,7 @@ impl Backend { let req = isahc::Request::head(&url); let mut req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("stat", path, e))?; self.signer @@ -547,10 +547,7 @@ impl Backend { .map_err(|e| new_request_send_error("stat", path, e)) } - pub(crate) async fn delete_blob( - &self, - path: &str, - ) -> Result> { + pub(crate) async fn delete_blob(&self, path: &str) -> Result> { let url = format!( "{}/{}/{}", self.endpoint, @@ -561,7 +558,7 @@ impl Backend { let req = isahc::Request::delete(&url); let mut req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("delete", path, e))?; self.signer @@ -578,7 +575,7 @@ impl Backend { &self, path: &str, next_marker: &str, - ) -> Result> { + ) -> Result> { let mut url = format!( "{}/{}?restype=container&comp=list&delimiter=/", self.endpoint, self.container @@ -592,7 +589,7 @@ impl Backend { } let mut req = isahc::Request::get(&url) - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("list", path, e))?; self.signer diff --git a/src/services/gcs/backend.rs b/src/services/gcs/backend.rs index 0b800f048c07..8928d65004b6 100644 --- a/src/services/gcs/backend.rs +++ b/src/services/gcs/backend.rs @@ -453,7 +453,7 @@ impl Backend { path: &str, offset: Option, size: Option, - ) -> Result> { + ) -> Result> { let url = format!( "{}/storage/v1/b/{}/o/{}?alt=media", self.endpoint, @@ -471,7 +471,7 @@ impl Backend { } let req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("read", path, e))?; Ok(req) @@ -482,7 +482,7 @@ impl Backend { path: &str, offset: Option, size: Option, - ) -> Result> { + ) -> Result> { let mut req = self.get_object_request(path, offset, size)?; self.signer @@ -524,7 +524,7 @@ impl Backend { pub(crate) async fn get_object_metadata( &self, path: &str, - ) -> Result> { + ) -> Result> { let url = format!( "{}/storage/v1/b/{}/o/{}", self.endpoint, diff --git a/src/services/http/backend.rs b/src/services/http/backend.rs index 4949e667f072..8b4d762edd63 100644 --- a/src/services/http/backend.rs +++ b/src/services/http/backend.rs @@ -515,7 +515,7 @@ impl Backend { path: &str, offset: Option, size: Option, - ) -> Result> { + ) -> Result> { let url = format!("{}{}", self.endpoint, percent_encode_path(path)); let mut req = isahc::Request::get(&url); @@ -528,7 +528,7 @@ impl Backend { } let req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("read", path, e))?; self.client @@ -537,13 +537,13 @@ impl Backend { .map_err(|e| new_request_send_error("read", path, e)) } - pub(crate) async fn http_head(&self, path: &str) -> Result> { + pub(crate) async fn http_head(&self, path: &str) -> Result> { let url = format!("{}{}", self.endpoint, percent_encode_path(path)); let req = isahc::Request::head(&url); let req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("stat", path, e))?; self.client @@ -573,17 +573,14 @@ impl Backend { Ok(req) } - pub(crate) async fn http_delete( - &self, - path: &str, - ) -> Result> { + pub(crate) async fn http_delete(&self, path: &str) -> Result> { let url = format!("{}/{}", self.endpoint, percent_encode_path(path)); let req = isahc::Request::delete(&url); // Set body let req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("delete", path, e))?; self.client diff --git a/src/services/memory/backend.rs b/src/services/memory/backend.rs index 9fa3e8c00d8e..10b173bdf979 100644 --- a/src/services/memory/backend.rs +++ b/src/services/memory/backend.rs @@ -70,7 +70,7 @@ impl Builder { /// Backend is used to serve `Accessor` support in memory. #[derive(Debug, Clone)] pub struct Backend { - inner: Arc>>, + inner: Arc>>, } impl Backend { @@ -258,7 +258,7 @@ impl Accessor for Backend { struct MapWriter { path: String, size: u64, - map: Arc>>, + map: Arc>>, buf: bytes::BytesMut, } diff --git a/src/services/s3/backend.rs b/src/services/s3/backend.rs index b559a125f80f..fccbbbadba5b 100644 --- a/src/services/s3/backend.rs +++ b/src/services/s3/backend.rs @@ -445,7 +445,7 @@ impl Builder { debug!("backend detect region with url: {url}"); let req = isahc::Request::head(&url) - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| { error!("backend detect_region {}: {:?}", url, e); other(BackendError::new( @@ -1110,7 +1110,7 @@ impl Accessor for Backend { async fn create(&self, args: &OpCreate) -> Result<()> { let p = self.get_abs_path(args.path()); - let mut req = self.put_object_request(&p, isahc::AsyncBody::from_bytes_static(""))?; + let mut req = self.put_object_request(&p, AsyncBody::from_bytes_static(""))?; self.signer .sign(&mut req) @@ -1274,7 +1274,7 @@ impl Accessor for Backend { // We will not send this request out, just for signing. let mut req = match args.operation() { Operation::Read => self.get_object_request(&path, None, None)?, - Operation::Write => self.put_object_request(&path, isahc::AsyncBody::empty())?, + Operation::Write => self.put_object_request(&path, AsyncBody::empty())?, op => { return Err(Error::new( ErrorKind::Unsupported, @@ -1308,7 +1308,7 @@ impl Backend { path: &str, offset: Option, size: Option, - ) -> Result> { + ) -> Result> { let url = format!("{}/{}", self.endpoint, percent_encode_path(path)); let mut req = isahc::Request::get(&url); @@ -1325,7 +1325,7 @@ impl Backend { req = self.insert_sse_headers(req, false); let req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("read", path, e))?; Ok(req) @@ -1336,7 +1336,7 @@ impl Backend { path: &str, offset: Option, size: Option, - ) -> Result> { + ) -> Result> { let mut req = self.get_object_request(path, offset, size)?; self.signer @@ -1353,7 +1353,7 @@ impl Backend { &self, path: &str, body: AsyncBody, - ) -> Result> { + ) -> Result> { let url = format!("{}/{}", self.endpoint, percent_encode_path(path)); let mut req = isahc::Request::put(&url); @@ -1384,10 +1384,7 @@ impl Backend { Ok(req) } - pub(crate) async fn head_object( - &self, - path: &str, - ) -> Result> { + pub(crate) async fn head_object(&self, path: &str) -> Result> { let url = format!("{}/{}", self.endpoint, percent_encode_path(path)); let mut req = isahc::Request::head(&url); @@ -1396,7 +1393,7 @@ impl Backend { req = self.insert_sse_headers(req, false); let mut req = req - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("stat", path, e))?; self.signer @@ -1409,14 +1406,11 @@ impl Backend { .map_err(|e| new_request_send_error("stat", path, e)) } - pub(crate) async fn delete_object( - &self, - path: &str, - ) -> Result> { + pub(crate) async fn delete_object(&self, path: &str) -> Result> { let url = format!("{}/{}", self.endpoint, percent_encode_path(path)); let mut req = isahc::Request::delete(&url) - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("delete", path, e))?; self.signer @@ -1433,7 +1427,7 @@ impl Backend { &self, path: &str, continuation_token: &str, - ) -> Result> { + ) -> Result> { let mut url = format!( "{}?list-type=2&delimiter=/&prefix={}", self.endpoint, @@ -1453,7 +1447,7 @@ impl Backend { } let mut req = isahc::Request::get(&url) - .body(isahc::AsyncBody::empty()) + .body(AsyncBody::empty()) .map_err(|e| new_request_build_error("list", path, e))?; self.signer From 956af412c86becb212d11bcedb432b8146a5b955 Mon Sep 17 00:00:00 2001 From: eastfisher Date: Tue, 23 Aug 2022 16:00:14 +0800 Subject: [PATCH 3/4] fix comment --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 505cf389c45b..d07aa26bb9ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,7 +104,8 @@ // Make sure all our public APIs have docs. #![warn(missing_docs)] -// Allowing/denying lints +// Add options below to allow/deny Clippy lints. +// Deny unused qualifications. #![deny(unused_qualifications)] // Private module with public types, they will be accessed via `opendal::Xxxx` From 2654c7cd5ffe0335dba5097fa567671ab961e817 Mon Sep 17 00:00:00 2001 From: eastfisher Date: Tue, 23 Aug 2022 16:51:27 +0800 Subject: [PATCH 4/4] Update src/lib.rs Co-authored-by: ClSlaid --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d07aa26bb9ef..b3cc21d78387 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,9 +104,9 @@ // Make sure all our public APIs have docs. #![warn(missing_docs)] -// Add options below to allow/deny Clippy lints. // Deny unused qualifications. #![deny(unused_qualifications)] +// Add options below to allow/deny Clippy lints. // Private module with public types, they will be accessed via `opendal::Xxxx` mod accessor;