Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove all unused qualifications #560

Merged
merged 4 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/http_util/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub fn parse_content_length(headers: &HeaderMap) -> Result<Option<u64>> {
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::<u64>()
.map_err(|e| anyhow!("parse {} header: {:?}", http::header::CONTENT_LENGTH, e))?,
.map_err(|e| anyhow!("parse {} header: {:?}", CONTENT_LENGTH, e))?,
)),
}
}
Expand All @@ -55,9 +55,9 @@ pub fn parse_last_modified(headers: &HeaderMap) -> Result<Option<OffsetDateTime>
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))
}
Expand Down
4 changes: 2 additions & 2 deletions src/io_util/into_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ use crate::BytesWrite;
pub fn into_sink<W: BytesWrite>(w: W) -> IntoSink<W> {
IntoSink {
w,
buf: bytes::Bytes::new(),
buf: Bytes::new(),
}
}

#[pin_project]
pub struct IntoSink<W: BytesWrite> {
#[pin]
w: W,
buf: bytes::Bytes,
buf: Bytes,
}

impl<W> IntoSink<W>
Expand Down
2 changes: 1 addition & 1 deletion src/io_util/into_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct IntoStream<R: BytesRead> {
#[pin]
r: R,
cap: usize,
buf: bytes::BytesMut,
buf: BytesMut,
}

impl<R> Stream for IntoStream<R>
Expand Down
4 changes: 2 additions & 2 deletions src/io_util/seekable_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl AsyncRead for SeekableReader {
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<std::io::Result<usize>> {
) -> Poll<Result<usize>> {
match &mut self.state {
State::Idle => {
let acc = self.acc.clone();
Expand Down Expand Up @@ -143,7 +143,7 @@ impl AsyncSeek for SeekableReader {
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
pos: SeekFrom,
) -> Poll<std::io::Result<u64>> {
) -> Poll<Result<u64>> {
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())
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +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)]
teckick marked this conversation as resolved.
Show resolved Hide resolved

// Private module with public types, they will be accessed via `opendal::Xxxx`
mod accessor;
Expand Down
21 changes: 9 additions & 12 deletions src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -461,7 +461,7 @@ impl Backend {
path: &str,
offset: Option<u64>,
size: Option<u64>,
) -> Result<isahc::Response<isahc::AsyncBody>> {
) -> Result<isahc::Response<AsyncBody>> {
let url = format!(
"{}/{}/{}",
self.endpoint,
Expand All @@ -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
Expand Down Expand Up @@ -523,7 +523,7 @@ impl Backend {
pub(crate) async fn get_blob_properties(
&self,
path: &str,
) -> Result<isahc::Response<isahc::AsyncBody>> {
) -> Result<isahc::Response<AsyncBody>> {
let url = format!(
"{}/{}/{}",
self.endpoint,
Expand All @@ -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
Expand All @@ -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<isahc::Response<isahc::AsyncBody>> {
pub(crate) async fn delete_blob(&self, path: &str) -> Result<isahc::Response<AsyncBody>> {
let url = format!(
"{}/{}/{}",
self.endpoint,
Expand All @@ -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
Expand All @@ -578,7 +575,7 @@ impl Backend {
&self,
path: &str,
next_marker: &str,
) -> Result<isahc::Response<isahc::AsyncBody>> {
) -> Result<isahc::Response<AsyncBody>> {
let mut url = format!(
"{}/{}?restype=container&comp=list&delimiter=/",
self.endpoint, self.container
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ impl Backend {
path: &str,
offset: Option<u64>,
size: Option<u64>,
) -> Result<isahc::Request<isahc::AsyncBody>> {
) -> Result<Request<AsyncBody>> {
let url = format!(
"{}/storage/v1/b/{}/o/{}?alt=media",
self.endpoint,
Expand All @@ -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)
Expand All @@ -482,7 +482,7 @@ impl Backend {
path: &str,
offset: Option<u64>,
size: Option<u64>,
) -> Result<isahc::Response<isahc::AsyncBody>> {
) -> Result<isahc::Response<AsyncBody>> {
let mut req = self.get_object_request(path, offset, size)?;

self.signer
Expand Down Expand Up @@ -524,7 +524,7 @@ impl Backend {
pub(crate) async fn get_object_metadata(
&self,
path: &str,
) -> Result<isahc::Response<isahc::AsyncBody>> {
) -> Result<isahc::Response<AsyncBody>> {
let url = format!(
"{}/storage/v1/b/{}/o/{}",
self.endpoint,
Expand Down
15 changes: 6 additions & 9 deletions src/services/http/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl Backend {
path: &str,
offset: Option<u64>,
size: Option<u64>,
) -> Result<isahc::Response<isahc::AsyncBody>> {
) -> Result<isahc::Response<AsyncBody>> {
let url = format!("{}{}", self.endpoint, percent_encode_path(path));

let mut req = isahc::Request::get(&url);
Expand All @@ -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
Expand All @@ -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<isahc::Response<isahc::AsyncBody>> {
pub(crate) async fn http_head(&self, path: &str) -> Result<isahc::Response<AsyncBody>> {
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
Expand Down Expand Up @@ -573,17 +573,14 @@ impl Backend {
Ok(req)
}

pub(crate) async fn http_delete(
&self,
path: &str,
) -> Result<isahc::Response<isahc::AsyncBody>> {
pub(crate) async fn http_delete(&self, path: &str) -> Result<isahc::Response<AsyncBody>> {
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
Expand Down
4 changes: 2 additions & 2 deletions src/services/memory/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Builder {
/// Backend is used to serve `Accessor` support in memory.
#[derive(Debug, Clone)]
pub struct Backend {
inner: Arc<Mutex<HashMap<String, bytes::Bytes>>>,
inner: Arc<Mutex<HashMap<String, Bytes>>>,
}

impl Backend {
Expand Down Expand Up @@ -258,7 +258,7 @@ impl Accessor for Backend {
struct MapWriter {
path: String,
size: u64,
map: Arc<Mutex<HashMap<String, bytes::Bytes>>>,
map: Arc<Mutex<HashMap<String, Bytes>>>,

buf: bytes::BytesMut,
}
Expand Down
32 changes: 13 additions & 19 deletions src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1308,7 +1308,7 @@ impl Backend {
path: &str,
offset: Option<u64>,
size: Option<u64>,
) -> Result<isahc::Request<isahc::AsyncBody>> {
) -> Result<isahc::Request<AsyncBody>> {
let url = format!("{}/{}", self.endpoint, percent_encode_path(path));

let mut req = isahc::Request::get(&url);
Expand All @@ -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)
Expand All @@ -1336,7 +1336,7 @@ impl Backend {
path: &str,
offset: Option<u64>,
size: Option<u64>,
) -> Result<isahc::Response<isahc::AsyncBody>> {
) -> Result<isahc::Response<AsyncBody>> {
let mut req = self.get_object_request(path, offset, size)?;

self.signer
Expand All @@ -1353,7 +1353,7 @@ impl Backend {
&self,
path: &str,
body: AsyncBody,
) -> Result<isahc::Request<isahc::AsyncBody>> {
) -> Result<isahc::Request<AsyncBody>> {
let url = format!("{}/{}", self.endpoint, percent_encode_path(path));

let mut req = isahc::Request::put(&url);
Expand Down Expand Up @@ -1384,10 +1384,7 @@ impl Backend {
Ok(req)
}

pub(crate) async fn head_object(
&self,
path: &str,
) -> Result<isahc::Response<isahc::AsyncBody>> {
pub(crate) async fn head_object(&self, path: &str) -> Result<isahc::Response<AsyncBody>> {
let url = format!("{}/{}", self.endpoint, percent_encode_path(path));

let mut req = isahc::Request::head(&url);
Expand All @@ -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
Expand All @@ -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<isahc::Response<isahc::AsyncBody>> {
pub(crate) async fn delete_object(&self, path: &str) -> Result<isahc::Response<AsyncBody>> {
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
Expand All @@ -1433,7 +1427,7 @@ impl Backend {
&self,
path: &str,
continuation_token: &str,
) -> Result<isahc::Response<isahc::AsyncBody>> {
) -> Result<isahc::Response<AsyncBody>> {
let mut url = format!(
"{}?list-type=2&delimiter=/&prefix={}",
self.endpoint,
Expand All @@ -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
Expand Down