From a5f313d2fbad3e6ded4b8386c2afe15c3b9e7f1d Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Tue, 9 Apr 2024 22:44:48 +0800 Subject: [PATCH] feat: Move Buffer as public API (#4450) * feat: Move Buffer as public API Signed-off-by: Xuanwo * FIx build Signed-off-by: Xuanwo --------- Signed-off-by: Xuanwo --- core/benches/oio/utils.rs | 3 +- core/src/layers/blocking.rs | 4 +- core/src/layers/chaos.rs | 4 +- core/src/layers/complete.rs | 12 +++--- core/src/layers/concurrent_limit.rs | 7 ++-- core/src/layers/dtrace.rs | 8 ++-- core/src/layers/error_context.rs | 8 ++-- core/src/layers/logging.rs | 8 ++-- core/src/layers/madsim.rs | 6 +-- core/src/layers/metrics.rs | 8 ++-- core/src/layers/minitrace.rs | 8 ++-- core/src/layers/oteltrace.rs | 8 ++-- core/src/layers/prometheus.rs | 8 ++-- core/src/layers/prometheus_client.rs | 8 ++-- core/src/layers/retry.rs | 11 +++--- core/src/layers/throttle.rs | 8 ++-- core/src/layers/timeout.rs | 6 +-- core/src/layers/tracing.rs | 8 ++-- core/src/raw/adapters/kv/api.rs | 4 +- core/src/raw/adapters/kv/backend.rs | 38 ++++++++++--------- core/src/raw/adapters/typed_kv/backend.rs | 4 +- core/src/raw/enum_utils.rs | 13 +++---- core/src/raw/http_util/body.rs | 2 +- core/src/raw/http_util/bytes_content_range.rs | 4 +- core/src/raw/http_util/bytes_range.rs | 4 +- core/src/raw/http_util/client.rs | 11 ++---- core/src/raw/http_util/multipart.rs | 7 ++-- core/src/raw/oio/buf/mod.rs | 3 -- core/src/raw/oio/buf/queue_buf.rs | 2 +- core/src/raw/oio/read/api.rs | 34 ++++++++--------- core/src/raw/oio/write/api.rs | 18 ++++----- core/src/raw/oio/write/append_write.rs | 2 +- core/src/raw/oio/write/block_write.rs | 2 +- core/src/raw/oio/write/exact_buf_write.rs | 4 +- core/src/raw/oio/write/multipart_write.rs | 2 +- core/src/raw/oio/write/one_shot_write.rs | 2 +- core/src/raw/oio/write/range_write.rs | 2 +- core/src/services/alluxio/core.rs | 2 +- core/src/services/alluxio/error.rs | 4 +- core/src/services/alluxio/reader.rs | 2 +- core/src/services/alluxio/writer.rs | 2 +- core/src/services/azblob/core.rs | 18 ++++----- core/src/services/azblob/error.rs | 6 +-- core/src/services/azblob/reader.rs | 4 +- core/src/services/azdls/core.rs | 17 ++++----- core/src/services/azdls/error.rs | 6 +-- core/src/services/azdls/reader.rs | 5 ++- core/src/services/azfile/core.rs | 29 ++++++-------- core/src/services/azfile/error.rs | 6 +-- core/src/services/azfile/reader.rs | 4 +- core/src/services/b2/core.rs | 28 +++++--------- core/src/services/b2/error.rs | 8 ++-- core/src/services/b2/reader.rs | 4 +- core/src/services/chainsafe/core.rs | 20 ++++------ core/src/services/chainsafe/error.rs | 8 ++-- core/src/services/chainsafe/reader.rs | 5 ++- core/src/services/cloudflare_kv/error.rs | 6 +-- core/src/services/cos/core.rs | 24 +++++------- core/src/services/cos/error.rs | 6 +-- core/src/services/cos/reader.rs | 5 ++- core/src/services/d1/error.rs | 6 +-- core/src/services/dbfs/core.rs | 12 +++--- core/src/services/dbfs/error.rs | 6 +-- core/src/services/dbfs/reader.rs | 2 +- core/src/services/dropbox/core.rs | 10 ++--- core/src/services/dropbox/error.rs | 6 +-- core/src/services/dropbox/reader.rs | 5 ++- core/src/services/fs/reader.rs | 6 +-- core/src/services/fs/writer.rs | 4 +- core/src/services/ftp/reader.rs | 4 +- core/src/services/gcs/core.rs | 23 +++++------ core/src/services/gcs/error.rs | 6 +-- core/src/services/gcs/reader.rs | 5 ++- core/src/services/gdrive/core.rs | 18 ++++----- core/src/services/gdrive/error.rs | 6 +-- core/src/services/gdrive/reader.rs | 5 ++- core/src/services/gdrive/writer.rs | 3 +- core/src/services/ghac/backend.rs | 2 +- core/src/services/ghac/error.rs | 6 +-- core/src/services/ghac/reader.rs | 5 ++- core/src/services/ghac/writer.rs | 2 +- core/src/services/github/core.rs | 8 ++-- core/src/services/github/error.rs | 8 ++-- core/src/services/github/reader.rs | 5 ++- core/src/services/hdfs/reader.rs | 9 ++--- core/src/services/hdfs/writer.rs | 4 +- core/src/services/hdfs_native/reader.rs | 5 ++- core/src/services/hdfs_native/writer.rs | 2 +- core/src/services/http/backend.rs | 4 +- core/src/services/http/error.rs | 6 +-- core/src/services/http/reader.rs | 5 ++- core/src/services/huggingface/core.rs | 6 +-- core/src/services/huggingface/error.rs | 2 +- core/src/services/huggingface/reader.rs | 5 ++- core/src/services/icloud/core.rs | 10 ++--- core/src/services/icloud/reader.rs | 5 ++- core/src/services/ipfs/backend.rs | 6 +-- core/src/services/ipfs/error.rs | 6 +-- core/src/services/ipfs/reader.rs | 5 ++- core/src/services/ipmfs/backend.rs | 12 +++--- core/src/services/ipmfs/error.rs | 6 +-- core/src/services/ipmfs/reader.rs | 5 ++- core/src/services/koofr/core.rs | 16 ++++---- core/src/services/koofr/error.rs | 8 ++-- core/src/services/koofr/reader.rs | 5 ++- core/src/services/libsql/error.rs | 6 +-- core/src/services/obs/core.rs | 24 +++++------- core/src/services/obs/error.rs | 6 +-- core/src/services/obs/reader.rs | 5 ++- core/src/services/onedrive/backend.rs | 19 ++++------ core/src/services/onedrive/error.rs | 6 +-- core/src/services/onedrive/reader.rs | 5 ++- core/src/services/oss/core.rs | 24 ++++++------ core/src/services/oss/error.rs | 6 +-- core/src/services/oss/reader.rs | 5 ++- core/src/services/pcloud/core.rs | 24 ++++++------ core/src/services/pcloud/error.rs | 8 ++-- core/src/services/pcloud/reader.rs | 5 ++- core/src/services/s3/core.rs | 20 +++++----- core/src/services/s3/error.rs | 6 +-- core/src/services/s3/reader.rs | 4 +- core/src/services/seafile/core.rs | 8 +--- core/src/services/seafile/error.rs | 8 ++-- core/src/services/seafile/reader.rs | 5 ++- core/src/services/sftp/reader.rs | 6 +-- core/src/services/sftp/writer.rs | 2 +- core/src/services/supabase/core.rs | 10 ++--- core/src/services/supabase/error.rs | 6 +-- core/src/services/supabase/reader.rs | 5 ++- core/src/services/swift/core.rs | 12 +++--- core/src/services/swift/error.rs | 6 +-- core/src/services/swift/reader.rs | 5 ++- core/src/services/upyun/core.rs | 24 +++++------- core/src/services/upyun/error.rs | 8 ++-- core/src/services/upyun/reader.rs | 5 ++- core/src/services/vercel_artifacts/backend.rs | 6 +-- core/src/services/vercel_artifacts/error.rs | 6 +-- core/src/services/vercel_artifacts/reader.rs | 5 ++- core/src/services/vercel_blob/core.rs | 14 +++---- core/src/services/vercel_blob/error.rs | 8 ++-- core/src/services/vercel_blob/reader.rs | 5 ++- core/src/services/webdav/core.rs | 12 +++--- core/src/services/webdav/error.rs | 6 +-- core/src/services/webdav/reader.rs | 5 ++- core/src/services/webhdfs/backend.rs | 19 +++------- core/src/services/webhdfs/error.rs | 4 +- core/src/services/webhdfs/reader.rs | 7 ++-- core/src/services/yandex_disk/core.rs | 12 +++--- core/src/services/yandex_disk/error.rs | 8 ++-- core/src/services/yandex_disk/reader.rs | 5 ++- core/src/types/blocking_reader.rs | 10 ++--- core/src/{raw/oio/buf => types}/buffer.rs | 0 core/src/types/mod.rs | 4 +- core/src/types/reader.rs | 10 ++--- core/src/types/writer.rs | 4 +- 155 files changed, 567 insertions(+), 671 deletions(-) rename core/src/{raw/oio/buf => types}/buffer.rs (100%) diff --git a/core/benches/oio/utils.rs b/core/benches/oio/utils.rs index 9987c89cbd0b..fd46fef6c07a 100644 --- a/core/benches/oio/utils.rs +++ b/core/benches/oio/utils.rs @@ -17,6 +17,7 @@ use bytes::Bytes; use opendal::raw::oio; +use opendal::*; use rand::prelude::ThreadRng; use rand::RngCore; @@ -24,7 +25,7 @@ use rand::RngCore; pub struct BlackHoleWriter; impl oio::Write for BlackHoleWriter { - async fn write(&mut self, bs: oio::Buffer) -> opendal::Result { + async fn write(&mut self, bs: Buffer) -> opendal::Result { Ok(bs.len()) } diff --git a/core/src/layers/blocking.rs b/core/src/layers/blocking.rs index 0367b4d5baa6..7bde3243c672 100644 --- a/core/src/layers/blocking.rs +++ b/core/src/layers/blocking.rs @@ -285,13 +285,13 @@ impl BlockingWrapper { } impl oio::BlockingRead for BlockingWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { self.handle.block_on(self.inner.read_at(offset, limit)) } } impl oio::BlockingWrite for BlockingWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { self.handle.block_on(self.inner.write(bs)) } diff --git a/core/src/layers/chaos.rs b/core/src/layers/chaos.rs index 063bc3f9f6bf..6164df4624c7 100644 --- a/core/src/layers/chaos.rs +++ b/core/src/layers/chaos.rs @@ -174,7 +174,7 @@ impl ChaosReader { } impl oio::Read for ChaosReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { if self.i_feel_lucky() { self.inner.read_at(offset, limit).await } else { @@ -184,7 +184,7 @@ impl oio::Read for ChaosReader { } impl oio::BlockingRead for ChaosReader { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { if self.i_feel_lucky() { self.inner.read_at(offset, limit) } else { diff --git a/core/src/layers/complete.rs b/core/src/layers/complete.rs index 353be43fb6de..228d68e2ceb2 100644 --- a/core/src/layers/complete.rs +++ b/core/src/layers/complete.rs @@ -593,9 +593,9 @@ pub type CompleteLister = pub struct CompleteReader(R); impl oio::Read for CompleteReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { if limit == 0 { - return Ok(oio::Buffer::new()); + return Ok(Buffer::new()); } self.0.read_at(offset, limit).await @@ -603,9 +603,9 @@ impl oio::Read for CompleteReader { } impl oio::BlockingRead for CompleteReader { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { if limit == 0 { - return Ok(oio::Buffer::new()); + return Ok(Buffer::new()); } self.0.read_at(offset, limit) @@ -638,7 +638,7 @@ impl oio::Write for CompleteWriter where W: oio::Write, { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let w = self.inner.as_mut().ok_or_else(|| { Error::new(ErrorKind::Unexpected, "writer has been closed or aborted") })?; @@ -673,7 +673,7 @@ impl oio::BlockingWrite for CompleteWriter where W: oio::BlockingWrite, { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let w = self.inner.as_mut().ok_or_else(|| { Error::new(ErrorKind::Unexpected, "writer has been closed or aborted") })?; diff --git a/core/src/layers/concurrent_limit.rs b/core/src/layers/concurrent_limit.rs index 0f62ff300e3b..b84a2decac9f 100644 --- a/core/src/layers/concurrent_limit.rs +++ b/core/src/layers/concurrent_limit.rs @@ -22,7 +22,6 @@ use async_trait::async_trait; use tokio::sync::OwnedSemaphorePermit; use tokio::sync::Semaphore; -use crate::raw::oio::Buffer; use crate::raw::*; use crate::*; @@ -260,13 +259,13 @@ impl oio::Read for ConcurrentLimitWrapper { } impl oio::BlockingRead for ConcurrentLimitWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { self.inner.read_at(offset, limit) } } impl oio::Write for ConcurrentLimitWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { self.inner.write(bs).await } @@ -280,7 +279,7 @@ impl oio::Write for ConcurrentLimitWrapper { } impl oio::BlockingWrite for ConcurrentLimitWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { self.inner.write(bs) } diff --git a/core/src/layers/dtrace.rs b/core/src/layers/dtrace.rs index 8020d7300446..f2525b8ba651 100644 --- a/core/src/layers/dtrace.rs +++ b/core/src/layers/dtrace.rs @@ -342,7 +342,7 @@ impl DtraceLayerWrapper { } impl oio::Read for DtraceLayerWrapper { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let c_path = CString::new(self.path.clone()).unwrap(); probe_lazy!(opendal, reader_read_start, c_path.as_ptr()); match self.inner.read_at(offset, limit).await { @@ -359,7 +359,7 @@ impl oio::Read for DtraceLayerWrapper { } impl oio::BlockingRead for DtraceLayerWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { let c_path = CString::new(self.path.clone()).unwrap(); probe_lazy!(opendal, blocking_reader_read_start, c_path.as_ptr()); self.inner @@ -381,7 +381,7 @@ impl oio::BlockingRead for DtraceLayerWrapper { } impl oio::Write for DtraceLayerWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let c_path = CString::new(self.path.clone()).unwrap(); probe_lazy!(opendal, writer_write_start, c_path.as_ptr()); self.inner @@ -429,7 +429,7 @@ impl oio::Write for DtraceLayerWrapper { } impl oio::BlockingWrite for DtraceLayerWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let c_path = CString::new(self.path.clone()).unwrap(); probe_lazy!(opendal, blocking_writer_write_start, c_path.as_ptr()); self.inner diff --git a/core/src/layers/error_context.rs b/core/src/layers/error_context.rs index 96098fb1bd75..f98c4b630fc4 100644 --- a/core/src/layers/error_context.rs +++ b/core/src/layers/error_context.rs @@ -342,7 +342,7 @@ pub struct ErrorContextWrapper { } impl oio::Read for ErrorContextWrapper { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { self.inner.read_at(offset, limit).await.map_err(|err| { err.with_operation(ReadOperation::Read) .with_context("service", self.scheme) @@ -354,7 +354,7 @@ impl oio::Read for ErrorContextWrapper { } impl oio::BlockingRead for ErrorContextWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { self.inner.read_at(offset, limit).map_err(|err| { err.with_operation(ReadOperation::BlockingRead) .with_context("service", self.scheme) @@ -366,7 +366,7 @@ impl oio::BlockingRead for ErrorContextWrapper { } impl oio::Write for ErrorContextWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { self.inner.write(bs.clone()).await.map_err(|err| { err.with_operation(WriteOperation::Write) .with_context("service", self.scheme) @@ -393,7 +393,7 @@ impl oio::Write for ErrorContextWrapper { } impl oio::BlockingWrite for ErrorContextWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { self.inner.write(bs.clone()).map_err(|err| { err.with_operation(WriteOperation::BlockingWrite) .with_context("service", self.scheme) diff --git a/core/src/layers/logging.rs b/core/src/layers/logging.rs index c60fc918c983..d9aab6ec7455 100644 --- a/core/src/layers/logging.rs +++ b/core/src/layers/logging.rs @@ -981,7 +981,7 @@ impl Drop for LoggingReader { } impl oio::Read for LoggingReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { match self.inner.read_at(offset, limit).await { Ok(bs) => { self.read @@ -1017,7 +1017,7 @@ impl oio::Read for LoggingReader { } impl oio::BlockingRead for LoggingReader { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { match self.inner.read_at(offset, limit) { Ok(bs) => { self.read @@ -1075,7 +1075,7 @@ impl LoggingWriter { } impl oio::Write for LoggingWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { match self.inner.write(bs.clone()).await { Ok(n) => { self.written += n as u64; @@ -1173,7 +1173,7 @@ impl oio::Write for LoggingWriter { } impl oio::BlockingWrite for LoggingWriter { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { match self.inner.write(bs.clone()) { Ok(n) => { self.written += n as u64; diff --git a/core/src/layers/madsim.rs b/core/src/layers/madsim.rs index 00a0202f2184..a3eb4cae8602 100644 --- a/core/src/layers/madsim.rs +++ b/core/src/layers/madsim.rs @@ -264,12 +264,12 @@ pub struct MadsimReader { } impl oio::Read for MadsimReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { if let Some(ref data) = self.data { let size = min(limit, data.len()); Ok(data.clone().split_to(size).into()) } else { - Ok(oio::Buffer::new()) + Ok(Buffer::new()) } } } @@ -284,7 +284,7 @@ pub struct MadsimWriter { } impl oio::Write for MadsimWriter { - async fn write(&mut self, bs: oio::Buffer) -> crate::Result { + async fn write(&mut self, bs: Buffer) -> crate::Result { #[cfg(madsim)] { let req = Request::Write(self.path.to_string(), bs); diff --git a/core/src/layers/metrics.rs b/core/src/layers/metrics.rs index 360539af7337..61a2880a1c1e 100644 --- a/core/src/layers/metrics.rs +++ b/core/src/layers/metrics.rs @@ -750,7 +750,7 @@ impl MetricWrapper { } impl oio::Read for MetricWrapper { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let start = Instant::now(); match self.inner.read_at(offset, limit).await { @@ -769,7 +769,7 @@ impl oio::Read for MetricWrapper { } impl oio::BlockingRead for MetricWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { let start = Instant::now(); self.inner @@ -788,7 +788,7 @@ impl oio::BlockingRead for MetricWrapper { } impl oio::Write for MetricWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let start = Instant::now(); self.inner @@ -822,7 +822,7 @@ impl oio::Write for MetricWrapper { } impl oio::BlockingWrite for MetricWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { self.inner .write(bs) .map(|n| { diff --git a/core/src/layers/minitrace.rs b/core/src/layers/minitrace.rs index 7f5f4288efdf..f4abba738779 100644 --- a/core/src/layers/minitrace.rs +++ b/core/src/layers/minitrace.rs @@ -295,13 +295,13 @@ impl MinitraceWrapper { impl oio::Read for MinitraceWrapper { #[trace(enter_on_poll = true)] - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { self.inner.read_at(offset, limit).await } } impl oio::BlockingRead for MinitraceWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { let _g = self.span.set_local_parent(); let _span = LocalSpan::enter_with_local_parent(ReadOperation::BlockingRead.into_static()); self.inner.read_at(offset, limit) @@ -309,7 +309,7 @@ impl oio::BlockingRead for MinitraceWrapper { } impl oio::Write for MinitraceWrapper { - fn write(&mut self, bs: oio::Buffer) -> impl Future> + Send { + fn write(&mut self, bs: Buffer) -> impl Future> + Send { let _g = self.span.set_local_parent(); let _span = LocalSpan::enter_with_local_parent(WriteOperation::Write.into_static()); self.inner.write(bs) @@ -329,7 +329,7 @@ impl oio::Write for MinitraceWrapper { } impl oio::BlockingWrite for MinitraceWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let _g = self.span.set_local_parent(); let _span = LocalSpan::enter_with_local_parent(WriteOperation::BlockingWrite.into_static()); self.inner.write(bs) diff --git a/core/src/layers/oteltrace.rs b/core/src/layers/oteltrace.rs index 0bdc7676debd..1aeaf9fc204d 100644 --- a/core/src/layers/oteltrace.rs +++ b/core/src/layers/oteltrace.rs @@ -275,19 +275,19 @@ impl OtelTraceWrapper { } impl oio::Read for OtelTraceWrapper { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { self.inner.read_at(offset, limit).await } } impl oio::BlockingRead for OtelTraceWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { self.inner.read_at(offset, limit) } } impl oio::Write for OtelTraceWrapper { - fn write(&mut self, bs: oio::Buffer) -> impl Future> + Send { + fn write(&mut self, bs: Buffer) -> impl Future> + Send { self.inner.write(bs) } @@ -301,7 +301,7 @@ impl oio::Write for OtelTraceWrapper { } impl oio::BlockingWrite for OtelTraceWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { self.inner.write(bs) } diff --git a/core/src/layers/prometheus.rs b/core/src/layers/prometheus.rs index 7c830f944568..f5cde22fe254 100644 --- a/core/src/layers/prometheus.rs +++ b/core/src/layers/prometheus.rs @@ -683,7 +683,7 @@ impl PrometheusMetricWrapper { } impl oio::Read for PrometheusMetricWrapper { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let labels = self.stats.generate_metric_label( self.scheme.into_static(), Operation::Read.into_static(), @@ -706,7 +706,7 @@ impl oio::Read for PrometheusMetricWrapper { } impl oio::BlockingRead for PrometheusMetricWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { let labels = self.stats.generate_metric_label( self.scheme.into_static(), Operation::BlockingRead.into_static(), @@ -729,7 +729,7 @@ impl oio::BlockingRead for PrometheusMetricWrapper { } impl oio::Write for PrometheusMetricWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let labels = self.stats.generate_metric_label( self.scheme.into_static(), Operation::Write.into_static(), @@ -767,7 +767,7 @@ impl oio::Write for PrometheusMetricWrapper { } impl oio::BlockingWrite for PrometheusMetricWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let labels = self.stats.generate_metric_label( self.scheme.into_static(), Operation::BlockingWrite.into_static(), diff --git a/core/src/layers/prometheus_client.rs b/core/src/layers/prometheus_client.rs index b8cdb17ab801..bf4c0809d5d9 100644 --- a/core/src/layers/prometheus_client.rs +++ b/core/src/layers/prometheus_client.rs @@ -536,7 +536,7 @@ impl PrometheusMetricWrapper { } impl oio::Read for PrometheusMetricWrapper { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let start = Instant::now(); match self.inner.read_at(offset, limit).await { @@ -557,7 +557,7 @@ impl oio::Read for PrometheusMetricWrapper { } impl oio::BlockingRead for PrometheusMetricWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { let start = Instant::now(); self.inner .read_at(offset, limit) @@ -577,7 +577,7 @@ impl oio::BlockingRead for PrometheusMetricWrapper { } impl oio::Write for PrometheusMetricWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let start = Instant::now(); self.inner @@ -614,7 +614,7 @@ impl oio::Write for PrometheusMetricWrapper { } impl oio::BlockingWrite for PrometheusMetricWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { self.inner .write(bs) .map(|n| { diff --git a/core/src/layers/retry.rs b/core/src/layers/retry.rs index d541fbc68c43..a59a7c32e153 100644 --- a/core/src/layers/retry.rs +++ b/core/src/layers/retry.rs @@ -27,7 +27,6 @@ use backon::Retryable; use futures::FutureExt; use log::warn; -use crate::raw::oio::Buffer; use crate::raw::oio::ListOperation; use crate::raw::oio::ReadOperation; use crate::raw::oio::WriteOperation; @@ -687,7 +686,7 @@ impl oio::Read for RetryWrapper { } impl oio::BlockingRead for RetryWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { { || self.inner.as_ref().unwrap().read_at(offset, limit) } .retry(&self.builder) .when(|e| e.is_temporary()) @@ -707,13 +706,13 @@ impl oio::BlockingRead for RetryWrapp } impl oio::Write for RetryWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { use backon::RetryableWithContext; let inner = self.inner.take().expect("inner must be valid"); let ((inner, _), res) = { - |(mut r, bs): (R, oio::Buffer)| async move { + |(mut r, bs): (R, Buffer)| async move { let res = r.write(bs.clone()).await; ((r, bs), res) @@ -805,7 +804,7 @@ impl oio::Write for RetryWrapper { } impl oio::BlockingWrite for RetryWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { { || self.inner.as_mut().unwrap().write(bs.clone()) } .retry(&self.builder) .when(|e| e.is_temporary()) @@ -1034,7 +1033,7 @@ mod tests { } impl oio::Read for MockReader { - async fn read_at(&self, _: u64, _: usize) -> Result { + async fn read_at(&self, _: u64, _: usize) -> Result { let mut attempt = self.attempt.lock().unwrap(); *attempt += 1; diff --git a/core/src/layers/throttle.rs b/core/src/layers/throttle.rs index b9b7389b5ff9..a2f83f4b45d7 100644 --- a/core/src/layers/throttle.rs +++ b/core/src/layers/throttle.rs @@ -182,21 +182,21 @@ impl ThrottleWrapper { } impl oio::Read for ThrottleWrapper { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { // TODO: How can we handle buffer reads with a limiter? self.inner.read_at(offset, limit).await } } impl oio::BlockingRead for ThrottleWrapper { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { // TODO: How can we handle buffer reads with a limiter? self.inner.read_at(offset, limit) } } impl oio::Write for ThrottleWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let buf_length = NonZeroU32::new(bs.len() as u32).unwrap(); loop { @@ -231,7 +231,7 @@ impl oio::Write for ThrottleWrapper { } impl oio::BlockingWrite for ThrottleWrapper { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let buf_length = NonZeroU32::new(bs.len() as u32).unwrap(); loop { diff --git a/core/src/layers/timeout.rs b/core/src/layers/timeout.rs index 55439547b6f8..31c15a39ad9a 100644 --- a/core/src/layers/timeout.rs +++ b/core/src/layers/timeout.rs @@ -291,14 +291,14 @@ impl TimeoutWrapper { } impl oio::Read for TimeoutWrapper { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let fut = self.inner.read_at(offset, limit); Self::io_timeout(self.timeout, ReadOperation::Read.into_static(), fut).await } } impl oio::Write for TimeoutWrapper { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let fut = self.inner.write(bs); Self::io_timeout(self.timeout, WriteOperation::Write.into_static(), fut).await } @@ -383,7 +383,7 @@ mod tests { struct MockReader; impl oio::Read for MockReader { - fn read_at(&self, _: u64, _: usize) -> impl Future> { + fn read_at(&self, _: u64, _: usize) -> impl Future> { pending() } } diff --git a/core/src/layers/tracing.rs b/core/src/layers/tracing.rs index 2276d1238ae0..b53beca0cf06 100644 --- a/core/src/layers/tracing.rs +++ b/core/src/layers/tracing.rs @@ -269,7 +269,7 @@ impl oio::Read for TracingWrapper { parent = &self.span, level = "trace", skip_all)] - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { self.inner.read_at(offset, limit).await } } @@ -279,7 +279,7 @@ impl oio::BlockingRead for TracingWrapper { parent = &self.span, level = "trace", skip_all)] - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { self.inner.read_at(offset, limit) } } @@ -289,7 +289,7 @@ impl oio::Write for TracingWrapper { parent = &self.span, level = "trace", skip_all)] - fn write(&mut self, bs: oio::Buffer) -> impl Future> + Send { + fn write(&mut self, bs: Buffer) -> impl Future> + Send { self.inner.write(bs) } @@ -315,7 +315,7 @@ impl oio::BlockingWrite for TracingWrapper { parent = &self.span, level = "trace", skip_all)] - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { self.inner.write(bs) } diff --git a/core/src/raw/adapters/kv/api.rs b/core/src/raw/adapters/kv/api.rs index 9adaabae6197..beede4c50939 100644 --- a/core/src/raw/adapters/kv/api.rs +++ b/core/src/raw/adapters/kv/api.rs @@ -21,10 +21,8 @@ use async_trait::async_trait; use crate::raw::*; use crate::Capability; -use crate::Error; -use crate::ErrorKind; -use crate::Result; use crate::Scheme; +use crate::*; /// KvAdapter is the adapter to underlying kv services. /// diff --git a/core/src/raw/adapters/kv/backend.rs b/core/src/raw/adapters/kv/backend.rs index e12ebb1bdd15..05af29da9899 100644 --- a/core/src/raw/adapters/kv/backend.rs +++ b/core/src/raw/adapters/kv/backend.rs @@ -236,7 +236,7 @@ pub struct KvWriter { kv: Arc, path: String, - buffer: Buffer, + buffer: FlexBuffer, } impl KvWriter { @@ -244,13 +244,13 @@ impl KvWriter { KvWriter { kv, path, - buffer: Buffer::Active(BytesMut::new()), + buffer: FlexBuffer::Active(BytesMut::new()), } } } -/// TODO: replace with FlexBuf. -enum Buffer { +/// TODO: replace with oio::FlexBuf. +enum FlexBuffer { Active(BytesMut), Frozen(Bytes), } @@ -261,54 +261,58 @@ enum Buffer { unsafe impl Sync for KvWriter {} impl oio::Write for KvWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { match &mut self.buffer { - Buffer::Active(buf) => { + FlexBuffer::Active(buf) => { buf.extend_from_slice(bs.chunk()); Ok(bs.chunk().len()) } - Buffer::Frozen(_) => unreachable!("KvWriter should not be frozen during poll_write"), + FlexBuffer::Frozen(_) => { + unreachable!("KvWriter should not be frozen during poll_write") + } } } async fn close(&mut self) -> Result<()> { let buf = match &mut self.buffer { - Buffer::Active(buf) => { + FlexBuffer::Active(buf) => { let buf = buf.split().freeze(); - self.buffer = Buffer::Frozen(buf.clone()); + self.buffer = FlexBuffer::Frozen(buf.clone()); buf } - Buffer::Frozen(buf) => buf.clone(), + FlexBuffer::Frozen(buf) => buf.clone(), }; self.kv.set(&self.path, &buf).await } async fn abort(&mut self) -> Result<()> { - self.buffer = Buffer::Active(BytesMut::new()); + self.buffer = FlexBuffer::Active(BytesMut::new()); Ok(()) } } impl oio::BlockingWrite for KvWriter { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { match &mut self.buffer { - Buffer::Active(buf) => { + FlexBuffer::Active(buf) => { buf.extend_from_slice(bs.chunk()); Ok(bs.chunk().len()) } - Buffer::Frozen(_) => unreachable!("KvWriter should not be frozen during poll_write"), + FlexBuffer::Frozen(_) => { + unreachable!("KvWriter should not be frozen during poll_write") + } } } fn close(&mut self) -> Result<()> { let buf = match &mut self.buffer { - Buffer::Active(buf) => { + FlexBuffer::Active(buf) => { let buf = buf.split().freeze(); - self.buffer = Buffer::Frozen(buf.clone()); + self.buffer = FlexBuffer::Frozen(buf.clone()); buf } - Buffer::Frozen(buf) => buf.clone(), + FlexBuffer::Frozen(buf) => buf.clone(), }; self.kv.blocking_set(&self.path, &buf)?; diff --git a/core/src/raw/adapters/typed_kv/backend.rs b/core/src/raw/adapters/typed_kv/backend.rs index 30d8ea9de603..b9935e252789 100644 --- a/core/src/raw/adapters/typed_kv/backend.rs +++ b/core/src/raw/adapters/typed_kv/backend.rs @@ -279,7 +279,7 @@ impl KvWriter { } impl oio::Write for KvWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let size = bs.chunk().len(); let mut buf = self.buf.take().unwrap_or_else(|| Vec::with_capacity(size)); @@ -309,7 +309,7 @@ impl oio::Write for KvWriter { } impl oio::BlockingWrite for KvWriter { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let size = bs.len(); let mut buf = self.buf.take().unwrap_or_else(|| Vec::with_capacity(size)); diff --git a/core/src/raw/enum_utils.rs b/core/src/raw/enum_utils.rs index 1a29426cb97d..bbfc8236086b 100644 --- a/core/src/raw/enum_utils.rs +++ b/core/src/raw/enum_utils.rs @@ -38,7 +38,6 @@ //! This module is used to provide some enums for the above code. We should remove this module once //! type_alias_impl_trait has been stabilized. -use crate::raw::oio::Buffer; use crate::raw::*; use crate::*; @@ -62,7 +61,7 @@ impl oio::Read for TwoWays { } impl oio::BlockingRead for TwoWays { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { match self { Self::One(v) => v.read_at(offset, limit), Self::Two(v) => v.read_at(offset, limit), @@ -71,7 +70,7 @@ impl oio::BlockingRead for TwoWa } impl oio::Write for TwoWays { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { match self { Self::One(v) => v.write(bs).await, Self::Two(v) => v.write(bs).await, @@ -106,7 +105,7 @@ pub enum ThreeWays { } impl oio::Read for ThreeWays { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { match self { ThreeWays::One(v) => v.read_at(offset, limit).await, ThreeWays::Two(v) => v.read_at(offset, limit).await, @@ -118,7 +117,7 @@ impl oio::Read for ThreeWays oio::BlockingRead for ThreeWays { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { match self { Self::One(v) => v.read_at(offset, limit), Self::Two(v) => v.read_at(offset, limit), @@ -130,7 +129,7 @@ impl o impl oio::Write for ThreeWays { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { match self { Self::One(v) => v.write(bs).await, Self::Two(v) => v.write(bs).await, @@ -193,7 +192,7 @@ where THREE: oio::BlockingRead, FOUR: oio::BlockingRead, { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { match self { Self::One(v) => v.read_at(offset, limit), Self::Two(v) => v.read_at(offset, limit), diff --git a/core/src/raw/http_util/body.rs b/core/src/raw/http_util/body.rs index 917fc53b1f77..7cfcfadb1ab3 100644 --- a/core/src/raw/http_util/body.rs +++ b/core/src/raw/http_util/body.rs @@ -29,6 +29,6 @@ pub enum AsyncBody { Bytes(Bytes), /// Body with stream. /// - /// TODO: remove this variant once by adopting oio::Buffer in writing. + /// TODO: remove this variant once by adopting Buffer in writing. Stream(oio::Streamer), } diff --git a/core/src/raw/http_util/bytes_content_range.rs b/core/src/raw/http_util/bytes_content_range.rs index 61e03cf93763..fb1e65539710 100644 --- a/core/src/raw/http_util/bytes_content_range.rs +++ b/core/src/raw/http_util/bytes_content_range.rs @@ -21,9 +21,7 @@ use std::ops::Range; use std::ops::RangeInclusive; use std::str::FromStr; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// BytesContentRange is the content range of bytes. /// diff --git a/core/src/raw/http_util/bytes_range.rs b/core/src/raw/http_util/bytes_range.rs index b2bde391311a..f968e54d5267 100644 --- a/core/src/raw/http_util/bytes_range.rs +++ b/core/src/raw/http_util/bytes_range.rs @@ -22,9 +22,7 @@ use std::ops::Bound; use std::ops::RangeBounds; use std::str::FromStr; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// BytesRange(offset, size) carries a range of content. /// diff --git a/core/src/raw/http_util/client.rs b/core/src/raw/http_util/client.rs index 3132d914ccbb..c64d47537341 100644 --- a/core/src/raw/http_util/client.rs +++ b/core/src/raw/http_util/client.rs @@ -31,10 +31,7 @@ use http::Response; use super::parse_content_encoding; use super::parse_content_length; use super::AsyncBody; -use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// HttpClient that used across opendal. #[derive(Clone)] @@ -86,7 +83,7 @@ impl HttpClient { } /// Send a request in async way. - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { // Uri stores all string alike data in `Bytes` which means // the clone here is cheap. let uri = req.uri().clone(); @@ -118,7 +115,7 @@ impl HttpClient { } #[cfg(target_arch = "wasm32")] { - let bs = oio::StreamExt::collect(s).await?; + let bs = crate::raw::oio::StreamExt::collect(s).await?; req_builder.body(reqwest::Body::from(bs)) } } @@ -185,7 +182,7 @@ impl HttpClient { .set_source(err) })?; - let buffer = oio::Buffer::from(bs); + let buffer = Buffer::from(bs); if let Some(expect) = content_length { check(expect, buffer.remaining() as u64)?; diff --git a/core/src/raw/http_util/multipart.rs b/core/src/raw/http_util/multipart.rs index bb981870753d..e51f25ceded6 100644 --- a/core/src/raw/http_util/multipart.rs +++ b/core/src/raw/http_util/multipart.rs @@ -41,7 +41,6 @@ use http::Version; use super::new_request_build_error; use super::AsyncBody; -use crate::raw::oio; use crate::raw::oio::Stream; use crate::*; @@ -411,7 +410,7 @@ impl MixedPart { } /// Consume a mixed part to build a response. - pub fn into_response(mut self) -> Response { + pub fn into_response(mut self) -> Response { let mut builder = Response::builder(); builder = builder.status(self.status_code.unwrap_or(StatusCode::OK)); @@ -420,8 +419,8 @@ impl MixedPart { mem::swap(builder.headers_mut().unwrap(), &mut self.headers); let body = match self.content { - None => oio::Buffer::new(), - Some(bs) => oio::Buffer::from(bs), + None => Buffer::new(), + Some(bs) => Buffer::from(bs), }; builder diff --git a/core/src/raw/oio/buf/mod.rs b/core/src/raw/oio/buf/mod.rs index bd8e354c3dda..c50a264f2702 100644 --- a/core/src/raw/oio/buf/mod.rs +++ b/core/src/raw/oio/buf/mod.rs @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -mod buffer; -pub use buffer::Buffer; - mod flex_buf; pub use flex_buf::FlexBuf; diff --git a/core/src/raw/oio/buf/queue_buf.rs b/core/src/raw/oio/buf/queue_buf.rs index b6114c1002bc..f8198380bff0 100644 --- a/core/src/raw/oio/buf/queue_buf.rs +++ b/core/src/raw/oio/buf/queue_buf.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -use crate::raw::oio::Buffer; +use crate::*; use bytes::{Buf, Bytes}; use std::collections::VecDeque; use std::sync::Arc; diff --git a/core/src/raw/oio/read/api.rs b/core/src/raw/oio/read/api.rs index 1feb44f16abe..0cfe3bfd5959 100644 --- a/core/src/raw/oio/read/api.rs +++ b/core/src/raw/oio/read/api.rs @@ -84,17 +84,13 @@ pub trait Read: Unpin + Send + Sync { /// Storage services should try to read as much as possible, only return bytes less than the /// limit while reaching the end of the file. #[cfg(not(target_arch = "wasm32"))] - fn read_at( - &self, - offset: u64, - limit: usize, - ) -> impl Future> + Send; + fn read_at(&self, offset: u64, limit: usize) -> impl Future> + Send; #[cfg(target_arch = "wasm32")] - fn read_at(&self, offset: u64, limit: usize) -> impl Future>; + fn read_at(&self, offset: u64, limit: usize) -> impl Future>; } impl Read for () { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let (_, _) = (offset, limit); Err(Error::new( @@ -106,22 +102,22 @@ impl Read for () { impl Read for Bytes { /// TODO: we can check if the offset is out of range. - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { if offset >= self.len() as u64 { - return Ok(oio::Buffer::new()); + return Ok(Buffer::new()); } let offset = offset as usize; let limit = limit.min(self.len() - offset); - Ok(oio::Buffer::from(self.slice(offset..offset + limit))) + Ok(Buffer::from(self.slice(offset..offset + limit))) } } pub trait ReadDyn: Unpin + Send + Sync { - fn read_at_dyn(&self, offset: u64, limit: usize) -> BoxedFuture>; + fn read_at_dyn(&self, offset: u64, limit: usize) -> BoxedFuture>; } impl ReadDyn for T { - fn read_at_dyn(&self, offset: u64, limit: usize) -> BoxedFuture> { + fn read_at_dyn(&self, offset: u64, limit: usize) -> BoxedFuture> { Box::pin(self.read_at(offset, limit)) } } @@ -131,7 +127,7 @@ impl ReadDyn for T { /// Take care about the `deref_mut()` here. This makes sure that we are calling functions /// upon `&mut T` instead of `&mut Box`. The later could result in infinite recursion. impl Read for Box { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { self.deref().read_at_dyn(offset, limit).await } } @@ -147,11 +143,11 @@ pub trait BlockingRead: Send + Sync { /// /// Storage services should try to read as much as possible, only return bytes less than the /// limit while reaching the end of the file. - fn read_at(&self, offset: u64, limit: usize) -> Result; + fn read_at(&self, offset: u64, limit: usize) -> Result; } impl BlockingRead for () { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { let _ = (offset, limit); unimplemented!("read is required to be implemented for oio::BlockingRead") @@ -160,20 +156,20 @@ impl BlockingRead for () { impl BlockingRead for Bytes { /// TODO: we can check if the offset is out of range. - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { if offset >= self.len() as u64 { - return Ok(oio::Buffer::new()); + return Ok(Buffer::new()); } let offset = offset as usize; let limit = limit.min(self.len() - offset); - Ok(oio::Buffer::from(self.slice(offset..offset + limit))) + Ok(Buffer::from(self.slice(offset..offset + limit))) } } /// `Box` won't implement `BlockingRead` automatically. /// To make BlockingReader work as expected, we must add this impl. impl BlockingRead for Box { - fn read_at(&self, offset: u64, limit: usize) -> Result { + fn read_at(&self, offset: u64, limit: usize) -> Result { (**self).read_at(offset, limit) } } diff --git a/core/src/raw/oio/write/api.rs b/core/src/raw/oio/write/api.rs index 00e9029c2043..473ef642ef71 100644 --- a/core/src/raw/oio/write/api.rs +++ b/core/src/raw/oio/write/api.rs @@ -83,9 +83,9 @@ pub trait Write: Unpin + Send + Sync { /// It's possible that `n < bs.len()`, caller should pass the remaining bytes /// repeatedly until all bytes has been written. #[cfg(not(target_arch = "wasm32"))] - fn write(&mut self, bs: oio::Buffer) -> impl Future> + Send; + fn write(&mut self, bs: Buffer) -> impl Future> + Send; #[cfg(target_arch = "wasm32")] - fn write(&mut self, bs: oio::Buffer) -> impl Future>; + fn write(&mut self, bs: Buffer) -> impl Future>; /// Close the writer and make sure all data has been flushed. #[cfg(not(target_arch = "wasm32"))] @@ -101,7 +101,7 @@ pub trait Write: Unpin + Send + Sync { } impl Write for () { - async fn write(&mut self, _: oio::Buffer) -> Result { + async fn write(&mut self, _: Buffer) -> Result { unimplemented!("write is required to be implemented for oio::Write") } @@ -121,7 +121,7 @@ impl Write for () { } pub trait WriteDyn: Unpin + Send + Sync { - fn write_dyn(&mut self, bs: oio::Buffer) -> BoxedFuture>; + fn write_dyn(&mut self, bs: Buffer) -> BoxedFuture>; fn close_dyn(&mut self) -> BoxedFuture>; @@ -129,7 +129,7 @@ pub trait WriteDyn: Unpin + Send + Sync { } impl WriteDyn for T { - fn write_dyn(&mut self, bs: oio::Buffer) -> BoxedFuture> { + fn write_dyn(&mut self, bs: Buffer) -> BoxedFuture> { Box::pin(self.write(bs)) } @@ -143,7 +143,7 @@ impl WriteDyn for T { } impl Write for Box { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { self.deref_mut().write_dyn(bs).await } @@ -176,14 +176,14 @@ pub trait BlockingWrite: Send + Sync + 'static { /// - The caller MUST ensure that the buffer is valid before `write` returns `Ready`. /// - The implementor SHOULD NOT store [`oio::ReadableBuf`] in anyways. The buf MUST /// be passed by or copied out to an owned buffer. - fn write(&mut self, bs: oio::Buffer) -> Result; + fn write(&mut self, bs: Buffer) -> Result; /// Close the writer and make sure all data has been flushed. fn close(&mut self) -> Result<()>; } impl BlockingWrite for () { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let _ = bs; unimplemented!("write is required to be implemented for oio::BlockingWrite") @@ -201,7 +201,7 @@ impl BlockingWrite for () { /// /// To make BlockingWriter work as expected, we must add this impl. impl BlockingWrite for Box { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { (**self).write(bs) } diff --git a/core/src/raw/oio/write/append_write.rs b/core/src/raw/oio/write/append_write.rs index 3514f73963bb..3d7e6a542b62 100644 --- a/core/src/raw/oio/write/append_write.rs +++ b/core/src/raw/oio/write/append_write.rs @@ -86,7 +86,7 @@ impl oio::Write for AppendWriter where W: AppendWrite, { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let offset = match self.offset { Some(offset) => offset, None => { diff --git a/core/src/raw/oio/write/block_write.rs b/core/src/raw/oio/write/block_write.rs index 88cace8e2caf..5c6ab118dc91 100644 --- a/core/src/raw/oio/write/block_write.rs +++ b/core/src/raw/oio/write/block_write.rs @@ -183,7 +183,7 @@ impl oio::Write for BlockWriter where W: BlockWrite, { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { loop { if self.futures.has_remaining() { // Fill cache with the first write. diff --git a/core/src/raw/oio/write/exact_buf_write.rs b/core/src/raw/oio/write/exact_buf_write.rs index c15b60c3f1d1..6e6f385975ed 100644 --- a/core/src/raw/oio/write/exact_buf_write.rs +++ b/core/src/raw/oio/write/exact_buf_write.rs @@ -45,7 +45,7 @@ impl ExactBufWriter { } impl oio::Write for ExactBufWriter { - async fn write(&mut self, mut bs: oio::Buffer) -> Result { + async fn write(&mut self, mut bs: Buffer) -> Result { if self.buffer.len() >= self.buffer_size { let written = self.inner.write(self.buffer.collect()).await?; self.buffer.advance(written); @@ -96,7 +96,7 @@ mod tests { } impl Write for MockWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { debug!("test_fuzz_exact_buf_writer: flush size: {}", &bs.len()); let chunk = bs.chunk(); diff --git a/core/src/raw/oio/write/multipart_write.rs b/core/src/raw/oio/write/multipart_write.rs index d89e6befad9b..69af59c8f851 100644 --- a/core/src/raw/oio/write/multipart_write.rs +++ b/core/src/raw/oio/write/multipart_write.rs @@ -229,7 +229,7 @@ impl oio::Write for MultipartWriter where W: MultipartWrite, { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let upload_id = match self.upload_id.clone() { Some(v) => v, None => { diff --git a/core/src/raw/oio/write/one_shot_write.rs b/core/src/raw/oio/write/one_shot_write.rs index 2bdc4101beef..3cdc11e9325c 100644 --- a/core/src/raw/oio/write/one_shot_write.rs +++ b/core/src/raw/oio/write/one_shot_write.rs @@ -55,7 +55,7 @@ impl OneShotWriter { } impl oio::Write for OneShotWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { match &self.buffer { Some(_) => Err(Error::new( ErrorKind::Unsupported, diff --git a/core/src/raw/oio/write/range_write.rs b/core/src/raw/oio/write/range_write.rs index eac4216c20ff..fcfd524c66d6 100644 --- a/core/src/raw/oio/write/range_write.rs +++ b/core/src/raw/oio/write/range_write.rs @@ -163,7 +163,7 @@ impl RangeWriter { } impl oio::Write for RangeWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let location = match self.location.clone() { Some(location) => location, None => { diff --git a/core/src/services/alluxio/core.rs b/core/src/services/alluxio/core.rs index eb3edd5bc145..1a3a42be8d25 100644 --- a/core/src/services/alluxio/core.rs +++ b/core/src/services/alluxio/core.rs @@ -301,7 +301,7 @@ impl AlluxioCore { /// TODO: we should implement range support correctly. /// /// Please refer to [alluxio-py](https://github.com/Alluxio/alluxio-py/blob/main/alluxio/const.py#L18) - pub async fn read(&self, stream_id: u64, _: BytesRange) -> Result> { + pub async fn read(&self, stream_id: u64, _: BytesRange) -> Result> { let req = Request::post(format!( "{}/api/v1/streams/{}/read", self.endpoint, stream_id, diff --git a/core/src/services/alluxio/error.rs b/core/src/services/alluxio/error.rs index 2b5c6b260fac..1ecbb2bca6b6 100644 --- a/core/src/services/alluxio/error.rs +++ b/core/src/services/alluxio/error.rs @@ -31,7 +31,7 @@ struct AlluxioError { message: String, } -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -90,7 +90,7 @@ mod tests { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) .body(body) diff --git a/core/src/services/alluxio/reader.rs b/core/src/services/alluxio/reader.rs index 7462cd234672..23b5c15aeb1e 100644 --- a/core/src/services/alluxio/reader.rs +++ b/core/src/services/alluxio/reader.rs @@ -40,7 +40,7 @@ impl AlluxioReader { } impl oio::Read for AlluxioReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.read(self.stream_id, range).await?; diff --git a/core/src/services/alluxio/writer.rs b/core/src/services/alluxio/writer.rs index 0b3023aac78d..bb0de9047f31 100644 --- a/core/src/services/alluxio/writer.rs +++ b/core/src/services/alluxio/writer.rs @@ -43,7 +43,7 @@ impl AlluxioWriter { } impl oio::Write for AlluxioWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let stream_id = match self.stream_id { Some(stream_id) => stream_id, None => { diff --git a/core/src/services/azblob/core.rs b/core/src/services/azblob/core.rs index da23012f5d69..a9f45a6c46f3 100644 --- a/core/src/services/azblob/core.rs +++ b/core/src/services/azblob/core.rs @@ -126,7 +126,7 @@ impl AzblobCore { } #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -219,7 +219,7 @@ impl AzblobCore { path: &str, range: BytesRange, args: &OpRead, - ) -> Result> { + ) -> Result> { let mut req = self.azblob_get_blob_request(path, range, args)?; self.sign(&mut req).await?; @@ -418,7 +418,7 @@ impl AzblobCore { size: Option, args: &OpWrite, body: AsyncBody, - ) -> Result> { + ) -> Result> { let mut req = self.azblob_put_block_request(path, block_id, size, args, body)?; self.sign(&mut req).await?; @@ -472,7 +472,7 @@ impl AzblobCore { path: &str, block_ids: Vec, args: &OpWrite, - ) -> Result> { + ) -> Result> { let mut req = self .azblob_complete_put_block_list_request(path, block_ids, args) .await?; @@ -520,7 +520,7 @@ impl AzblobCore { &self, path: &str, args: &OpStat, - ) -> Result> { + ) -> Result> { let mut req = self.azblob_head_blob_request(path, args)?; self.sign(&mut req).await?; @@ -544,14 +544,14 @@ impl AzblobCore { .map_err(new_request_build_error) } - pub async fn azblob_delete_blob(&self, path: &str) -> Result> { + pub async fn azblob_delete_blob(&self, path: &str) -> Result> { let mut req = self.azblob_delete_blob_request(path)?; self.sign(&mut req).await?; self.send(req).await } - pub async fn azblob_copy_blob(&self, from: &str, to: &str) -> Result> { + pub async fn azblob_copy_blob(&self, from: &str, to: &str) -> Result> { let source = build_abs_path(&self.root, from); let target = build_abs_path(&self.root, to); @@ -584,7 +584,7 @@ impl AzblobCore { next_marker: &str, delimiter: &str, limit: Option, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let mut url = format!( @@ -613,7 +613,7 @@ impl AzblobCore { self.send(req).await } - pub async fn azblob_batch_delete(&self, paths: &[String]) -> Result> { + pub async fn azblob_batch_delete(&self, paths: &[String]) -> Result> { let url = format!( "{}/{}?restype=container&comp=batch", self.endpoint, self.container diff --git a/core/src/services/azblob/error.rs b/core/src/services/azblob/error.rs index 22cbeb93be6c..f1e3de094558 100644 --- a/core/src/services/azblob/error.rs +++ b/core/src/services/azblob/error.rs @@ -24,9 +24,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// AzblobError is the error returned by azure blob service. #[derive(Default, Deserialize)] @@ -61,7 +59,7 @@ impl Debug for AzblobError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/azblob/reader.rs b/core/src/services/azblob/reader.rs index 077a68f22a0d..6f9540baf6fa 100644 --- a/core/src/services/azblob/reader.rs +++ b/core/src/services/azblob/reader.rs @@ -42,7 +42,7 @@ impl AzblobReader { } impl oio::Read for AzblobReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self @@ -54,7 +54,7 @@ impl oio::Read for AzblobReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/azdls/core.rs b/core/src/services/azdls/core.rs index 5678361903e9..f010190585c6 100644 --- a/core/src/services/azdls/core.rs +++ b/core/src/services/azdls/core.rs @@ -91,13 +91,13 @@ impl AzdlsCore { } #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } } impl AzdlsCore { - pub async fn azdls_read(&self, path: &str, range: BytesRange) -> Result> { + pub async fn azdls_read(&self, path: &str, range: BytesRange) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -161,7 +161,7 @@ impl AzdlsCore { Ok(req) } - pub async fn azdls_rename(&self, from: &str, to: &str) -> Result> { + pub async fn azdls_rename(&self, from: &str, to: &str) -> Result> { let source = build_abs_path(&self.root, from); let target = build_abs_path(&self.root, to); @@ -217,7 +217,7 @@ impl AzdlsCore { Ok(req) } - pub async fn azdls_get_properties(&self, path: &str) -> Result> { + pub async fn azdls_get_properties(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); @@ -239,7 +239,7 @@ impl AzdlsCore { self.client.send(req).await } - pub async fn azdls_delete(&self, path: &str) -> Result> { + pub async fn azdls_delete(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); @@ -266,7 +266,7 @@ impl AzdlsCore { path: &str, continuation: &str, limit: Option, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); @@ -295,10 +295,7 @@ impl AzdlsCore { self.send(req).await } - pub async fn azdls_ensure_parent_path( - &self, - path: &str, - ) -> Result>> { + pub async fn azdls_ensure_parent_path(&self, path: &str) -> Result>> { let abs_target_path = path.trim_end_matches('/').to_string(); let abs_target_path = abs_target_path.as_str(); let mut parts: Vec<&str> = abs_target_path diff --git a/core/src/services/azdls/error.rs b/core/src/services/azdls/error.rs index 77b475c2954d..ba5bf95f7015 100644 --- a/core/src/services/azdls/error.rs +++ b/core/src/services/azdls/error.rs @@ -24,9 +24,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// AzdlsError is the error returned by azure dfs service. #[derive(Default, Deserialize)] @@ -61,7 +59,7 @@ impl Debug for AzdlsError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/azdls/reader.rs b/core/src/services/azdls/reader.rs index 914c8a62fec8..a144f8c55c64 100644 --- a/core/src/services/azdls/reader.rs +++ b/core/src/services/azdls/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::AzdlsCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct AzdlsReader { core: Arc, @@ -41,7 +42,7 @@ impl AzdlsReader { } impl oio::Read for AzdlsReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.azdls_read(&self.path, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for AzdlsReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/azfile/core.rs b/core/src/services/azfile/core.rs index a332ca081edd..ca9820950d99 100644 --- a/core/src/services/azfile/core.rs +++ b/core/src/services/azfile/core.rs @@ -93,15 +93,11 @@ impl AzfileCore { } #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } - pub async fn azfile_read( - &self, - path: &str, - range: BytesRange, - ) -> Result> { + pub async fn azfile_read(&self, path: &str, range: BytesRange) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -129,7 +125,7 @@ impl AzfileCore { path: &str, size: usize, args: &OpWrite, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path) .trim_start_matches('/') .to_string(); @@ -172,7 +168,7 @@ impl AzfileCore { size: u64, position: u64, body: AsyncBody, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path) .trim_start_matches('/') .to_string(); @@ -200,7 +196,7 @@ impl AzfileCore { self.send(req).await } - pub async fn azfile_get_file_properties(&self, path: &str) -> Result> { + pub async fn azfile_get_file_properties(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( "{}/{}/{}", @@ -218,10 +214,7 @@ impl AzfileCore { self.send(req).await } - pub async fn azfile_get_directory_properties( - &self, - path: &str, - ) -> Result> { + pub async fn azfile_get_directory_properties(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -240,7 +233,7 @@ impl AzfileCore { self.send(req).await } - pub async fn azfile_rename(&self, path: &str, new_path: &str) -> Result> { + pub async fn azfile_rename(&self, path: &str, new_path: &str) -> Result> { let p = build_abs_path(&self.root, path) .trim_start_matches('/') .to_string(); @@ -292,7 +285,7 @@ impl AzfileCore { self.send(req).await } - pub async fn azfile_create_dir(&self, path: &str) -> Result> { + pub async fn azfile_create_dir(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path) .trim_start_matches('/') .to_string(); @@ -315,7 +308,7 @@ impl AzfileCore { self.send(req).await } - pub async fn azfile_delete_file(&self, path: &str) -> Result> { + pub async fn azfile_delete_file(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path) .trim_start_matches('/') .to_string(); @@ -336,7 +329,7 @@ impl AzfileCore { self.send(req).await } - pub async fn azfile_delete_dir(&self, path: &str) -> Result> { + pub async fn azfile_delete_dir(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path) .trim_start_matches('/') .to_string(); @@ -362,7 +355,7 @@ impl AzfileCore { path: &str, limit: &Option, continuation: &String, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path) .trim_start_matches('/') .to_string(); diff --git a/core/src/services/azfile/error.rs b/core/src/services/azfile/error.rs index 0e8992b7abe2..08888e1fa8a9 100644 --- a/core/src/services/azfile/error.rs +++ b/core/src/services/azfile/error.rs @@ -24,9 +24,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// AzfileError is the error returned by azure file service. #[derive(Default, Deserialize)] @@ -61,7 +59,7 @@ impl Debug for AzfileError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/azfile/reader.rs b/core/src/services/azfile/reader.rs index 651188b8ef8f..04dfebe5a005 100644 --- a/core/src/services/azfile/reader.rs +++ b/core/src/services/azfile/reader.rs @@ -42,7 +42,7 @@ impl AzfileReader { } impl oio::Read for AzfileReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.azfile_read(&self.path, range).await?; @@ -51,7 +51,7 @@ impl oio::Read for AzfileReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/b2/core.rs b/core/src/services/b2/core.rs index 77daad48f97f..05f4c2ee1323 100644 --- a/core/src/services/b2/core.rs +++ b/core/src/services/b2/core.rs @@ -71,7 +71,7 @@ impl Debug for B2Core { impl B2Core { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -134,7 +134,7 @@ impl B2Core { path: &str, range: BytesRange, _args: &OpRead, - ) -> Result> { + ) -> Result> { let path = build_abs_path(&self.root, path); let auth_info = self.get_auth_info().await?; @@ -242,7 +242,7 @@ impl B2Core { size: Option, args: &OpWrite, body: AsyncBody, - ) -> Result> { + ) -> Result> { let resp = self.get_upload_url().await?; let p = build_abs_path(&self.root, path); @@ -275,11 +275,7 @@ impl B2Core { self.send(req).await } - pub async fn start_large_file( - &self, - path: &str, - args: &OpWrite, - ) -> Result> { + pub async fn start_large_file(&self, path: &str, args: &OpWrite) -> Result> { let p = build_abs_path(&self.root, path); let auth_info = self.get_auth_info().await?; @@ -348,7 +344,7 @@ impl B2Core { part_number: usize, size: u64, body: AsyncBody, - ) -> Result> { + ) -> Result> { let resp = self.get_upload_part_url(file_id).await?; let mut req = Request::post(resp.upload_url); @@ -371,7 +367,7 @@ impl B2Core { &self, file_id: &str, part_sha1_array: Vec, - ) -> Result> { + ) -> Result> { let auth_info = self.get_auth_info().await?; let url = format!("{}/b2api/v2/b2_finish_large_file", auth_info.api_url); @@ -395,7 +391,7 @@ impl B2Core { self.send(req).await } - pub async fn cancel_large_file(&self, file_id: &str) -> Result> { + pub async fn cancel_large_file(&self, file_id: &str) -> Result> { let auth_info = self.get_auth_info().await?; let url = format!("{}/b2api/v2/b2_cancel_large_file", auth_info.api_url); @@ -424,7 +420,7 @@ impl B2Core { delimiter: Option<&str>, limit: Option, start_after: Option, - ) -> Result> { + ) -> Result> { let auth_info = self.get_auth_info().await?; let mut url = format!( @@ -464,11 +460,7 @@ impl B2Core { self.send(req).await } - pub async fn copy_file( - &self, - source_file_id: String, - to: &str, - ) -> Result> { + pub async fn copy_file(&self, source_file_id: String, to: &str) -> Result> { let to = build_abs_path(&self.root, to); let auth_info = self.get_auth_info().await?; @@ -495,7 +487,7 @@ impl B2Core { self.send(req).await } - pub async fn hide_file(&self, path: &str) -> Result> { + pub async fn hide_file(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let auth_info = self.get_auth_info().await?; diff --git a/core/src/services/b2/error.rs b/core/src/services/b2/error.rs index 9b4705891967..6dcf1bd02b98 100644 --- a/core/src/services/b2/error.rs +++ b/core/src/services/b2/error.rs @@ -20,9 +20,7 @@ use http::Response; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// the error response of b2 #[derive(Default, Debug, Deserialize)] @@ -34,7 +32,7 @@ struct B2Error { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -123,7 +121,7 @@ mod test { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/b2/reader.rs b/core/src/services/b2/reader.rs index 63cb47b6b78c..6071d1d3c99e 100644 --- a/core/src/services/b2/reader.rs +++ b/core/src/services/b2/reader.rs @@ -42,7 +42,7 @@ impl B2Reader { } impl oio::Read for B2Reader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self @@ -54,7 +54,7 @@ impl oio::Read for B2Reader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/chainsafe/core.rs b/core/src/services/chainsafe/core.rs index e38dcb4c792b..6a1d76e37b49 100644 --- a/core/src/services/chainsafe/core.rs +++ b/core/src/services/chainsafe/core.rs @@ -52,17 +52,13 @@ impl Debug for ChainsafeCore { impl ChainsafeCore { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } } impl ChainsafeCore { - pub async fn download_object( - &self, - path: &str, - range: BytesRange, - ) -> Result> { + pub async fn download_object(&self, path: &str, range: BytesRange) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -88,7 +84,7 @@ impl ChainsafeCore { self.send(req).await } - pub async fn object_info(&self, path: &str) -> Result> { + pub async fn object_info(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -114,7 +110,7 @@ impl ChainsafeCore { self.send(req).await } - pub async fn move_object(&self, from: &str, to: &str) -> Result> { + pub async fn move_object(&self, from: &str, to: &str) -> Result> { let from = build_abs_path(&self.root, from); let to = build_abs_path(&self.root, to); @@ -141,7 +137,7 @@ impl ChainsafeCore { self.send(req).await } - pub async fn delete_object(&self, path: &str) -> Result> { + pub async fn delete_object(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -167,7 +163,7 @@ impl ChainsafeCore { self.send(req).await } - pub async fn upload_object(&self, path: &str, bs: Bytes) -> Result> { + pub async fn upload_object(&self, path: &str, bs: Bytes) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -191,7 +187,7 @@ impl ChainsafeCore { self.send(req).await } - pub async fn list_objects(&self, path: &str) -> Result> { + pub async fn list_objects(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -217,7 +213,7 @@ impl ChainsafeCore { self.send(req).await } - pub async fn create_dir(&self, path: &str) -> Result> { + pub async fn create_dir(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/chainsafe/error.rs b/core/src/services/chainsafe/error.rs index b7e3cf2d889f..4ab3a4a8dd12 100644 --- a/core/src/services/chainsafe/error.rs +++ b/core/src/services/chainsafe/error.rs @@ -20,9 +20,7 @@ use http::Response; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; #[derive(Default, Debug, Deserialize)] #[allow(dead_code)] @@ -38,7 +36,7 @@ struct ChainsafeSubError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -94,7 +92,7 @@ mod test { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/chainsafe/reader.rs b/core/src/services/chainsafe/reader.rs index b6813660dd67..9e7b635ad97c 100644 --- a/core/src/services/chainsafe/reader.rs +++ b/core/src/services/chainsafe/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::ChainsafeCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct ChainsafeReader { core: Arc, @@ -41,7 +42,7 @@ impl ChainsafeReader { } impl oio::Read for ChainsafeReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.download_object(&self.path, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for ChainsafeReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/cloudflare_kv/error.rs b/core/src/services/cloudflare_kv/error.rs index 34c81953516e..08f68598b90a 100644 --- a/core/src/services/cloudflare_kv/error.rs +++ b/core/src/services/cloudflare_kv/error.rs @@ -23,12 +23,10 @@ use serde_json::de; use super::backend::CfKvError; use super::backend::CfKvResponse; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub(crate) async fn parse_error(resp: Response) -> Result { +pub(crate) async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/cos/core.rs b/core/src/services/cos/core.rs index 003be69b319b..220433f7c913 100644 --- a/core/src/services/cos/core.rs +++ b/core/src/services/cos/core.rs @@ -95,7 +95,7 @@ impl CosCore { } #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } } @@ -106,7 +106,7 @@ impl CosCore { path: &str, range: BytesRange, args: &OpRead, - ) -> Result> { + ) -> Result> { let mut req = self.cos_get_object_request(path, range, args)?; self.sign(&mut req).await?; @@ -176,11 +176,7 @@ impl CosCore { Ok(req) } - pub async fn cos_head_object( - &self, - path: &str, - args: &OpStat, - ) -> Result> { + pub async fn cos_head_object(&self, path: &str, args: &OpStat) -> Result> { let mut req = self.cos_head_object_request(path, args)?; self.sign(&mut req).await?; @@ -210,7 +206,7 @@ impl CosCore { Ok(req) } - pub async fn cos_delete_object(&self, path: &str) -> Result> { + pub async fn cos_delete_object(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!("{}/{}", self.endpoint, percent_encode_path(&p)); @@ -262,7 +258,7 @@ impl CosCore { Ok(req) } - pub async fn cos_copy_object(&self, from: &str, to: &str) -> Result> { + pub async fn cos_copy_object(&self, from: &str, to: &str) -> Result> { let source = build_abs_path(&self.root, from); let target = build_abs_path(&self.root, to); @@ -285,7 +281,7 @@ impl CosCore { next_marker: &str, delimiter: &str, limit: Option, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let mut queries = vec![]; @@ -321,7 +317,7 @@ impl CosCore { &self, path: &str, args: &OpWrite, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!("{}/{}?uploads", self.endpoint, percent_encode_path(&p)); @@ -356,7 +352,7 @@ impl CosCore { part_number: usize, size: u64, body: AsyncBody, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -382,7 +378,7 @@ impl CosCore { path: &str, upload_id: &str, parts: Vec, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -415,7 +411,7 @@ impl CosCore { &self, path: &str, upload_id: &str, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/cos/error.rs b/core/src/services/cos/error.rs index 95d5e347fbaa..15206411dbe7 100644 --- a/core/src/services/cos/error.rs +++ b/core/src/services/cos/error.rs @@ -22,9 +22,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// CosError is the error returned by cos service. #[derive(Default, Debug, Deserialize)] @@ -38,7 +36,7 @@ struct CosError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/cos/reader.rs b/core/src/services/cos/reader.rs index 57af3a1607e4..75c031174963 100644 --- a/core/src/services/cos/reader.rs +++ b/core/src/services/cos/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::CosCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct CosReader { core: Arc, @@ -41,7 +42,7 @@ impl CosReader { } impl oio::Read for CosReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self @@ -53,7 +54,7 @@ impl oio::Read for CosReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/d1/error.rs b/core/src/services/d1/error.rs index ada419ef4b3d..a3afb7bc1eee 100644 --- a/core/src/services/d1/error.rs +++ b/core/src/services/d1/error.rs @@ -23,12 +23,10 @@ use serde_json::de; use super::model::D1Error; use super::model::D1Response; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/dbfs/core.rs b/core/src/services/dbfs/core.rs index 55e4516f1bfa..c28a36ce89c2 100644 --- a/core/src/services/dbfs/core.rs +++ b/core/src/services/dbfs/core.rs @@ -48,7 +48,7 @@ impl Debug for DbfsCore { } impl DbfsCore { - pub async fn dbfs_create_dir(&self, path: &str) -> Result> { + pub async fn dbfs_create_dir(&self, path: &str) -> Result> { let url = format!("{}/api/2.0/dbfs/mkdirs", self.endpoint); let mut req = Request::post(&url); @@ -69,7 +69,7 @@ impl DbfsCore { self.client.send(req).await } - pub async fn dbfs_delete(&self, path: &str) -> Result> { + pub async fn dbfs_delete(&self, path: &str) -> Result> { let url = format!("{}/api/2.0/dbfs/delete", self.endpoint); let mut req = Request::post(&url); @@ -93,7 +93,7 @@ impl DbfsCore { self.client.send(req).await } - pub async fn dbfs_rename(&self, from: &str, to: &str) -> Result> { + pub async fn dbfs_rename(&self, from: &str, to: &str) -> Result> { let source = build_rooted_abs_path(&self.root, from); let target = build_rooted_abs_path(&self.root, to); @@ -115,7 +115,7 @@ impl DbfsCore { self.client.send(req).await } - pub async fn dbfs_list(&self, path: &str) -> Result> { + pub async fn dbfs_list(&self, path: &str) -> Result> { let p = build_rooted_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); @@ -162,7 +162,7 @@ impl DbfsCore { path: &str, offset: u64, length: u64, - ) -> Result> { + ) -> Result> { let p = build_rooted_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); @@ -200,7 +200,7 @@ impl DbfsCore { } } - pub async fn dbfs_get_status(&self, path: &str) -> Result> { + pub async fn dbfs_get_status(&self, path: &str) -> Result> { let p = build_rooted_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); diff --git a/core/src/services/dbfs/error.rs b/core/src/services/dbfs/error.rs index c65612fe3ddc..117da1ca67f8 100644 --- a/core/src/services/dbfs/error.rs +++ b/core/src/services/dbfs/error.rs @@ -23,9 +23,7 @@ use http::StatusCode; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// DbfsError is the error returned by DBFS service. #[derive(Default, Deserialize)] @@ -45,7 +43,7 @@ impl Debug for DbfsError { } } -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/dbfs/reader.rs b/core/src/services/dbfs/reader.rs index ce267d297b17..9ae4bc4d83c2 100644 --- a/core/src/services/dbfs/reader.rs +++ b/core/src/services/dbfs/reader.rs @@ -23,7 +23,7 @@ use bytes::Bytes; use serde::Deserialize; use super::core::DbfsCore; -use crate::raw::oio::Buffer; + use crate::raw::*; use crate::*; diff --git a/core/src/services/dropbox/core.rs b/core/src/services/dropbox/core.rs index 6bbab5e3f949..26c6e6f7b8fa 100644 --- a/core/src/services/dropbox/core.rs +++ b/core/src/services/dropbox/core.rs @@ -129,7 +129,7 @@ impl DropboxCore { path: &str, range: BytesRange, _: &OpRead, - ) -> Result> { + ) -> Result> { let url: String = "https://content.dropboxapi.com/2/files/download".to_string(); let download_args = DropboxDownloadArgs { path: build_rooted_abs_path(&self.root, path), @@ -159,7 +159,7 @@ impl DropboxCore { size: Option, args: &OpWrite, body: AsyncBody, - ) -> Result> { + ) -> Result> { let url = "https://content.dropboxapi.com/2/files/upload".to_string(); let dropbox_update_args = DropboxUploadArgs { path: build_rooted_abs_path(&self.root, path), @@ -186,7 +186,7 @@ impl DropboxCore { self.client.send(request).await } - pub async fn dropbox_delete(&self, path: &str) -> Result> { + pub async fn dropbox_delete(&self, path: &str) -> Result> { let url = "https://api.dropboxapi.com/2/files/delete_v2".to_string(); let args = DropboxDeleteArgs { path: self.build_path(path), @@ -204,7 +204,7 @@ impl DropboxCore { self.client.send(request).await } - pub async fn dropbox_delete_batch(&self, paths: Vec) -> Result> { + pub async fn dropbox_delete_batch(&self, paths: Vec) -> Result> { let url = "https://api.dropboxapi.com/2/files/delete_batch".to_string(); let args = DropboxDeleteBatchArgs { entries: paths @@ -300,7 +300,7 @@ impl DropboxCore { } } - pub async fn dropbox_get_metadata(&self, path: &str) -> Result> { + pub async fn dropbox_get_metadata(&self, path: &str) -> Result> { let url = "https://api.dropboxapi.com/2/files/get_metadata".to_string(); let args = DropboxMetadataArgs { path: self.build_path(path), diff --git a/core/src/services/dropbox/error.rs b/core/src/services/dropbox/error.rs index a956a6f714fc..ddbb1b6ae022 100644 --- a/core/src/services/dropbox/error.rs +++ b/core/src/services/dropbox/error.rs @@ -21,9 +21,7 @@ use http::StatusCode; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; #[derive(Default, Debug, Deserialize)] #[serde(default)] @@ -32,7 +30,7 @@ pub struct DropboxErrorResponse { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/dropbox/reader.rs b/core/src/services/dropbox/reader.rs index dd22b7ab0427..9d4152831b09 100644 --- a/core/src/services/dropbox/reader.rs +++ b/core/src/services/dropbox/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::DropboxCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct DropboxReader { core: Arc, @@ -41,7 +42,7 @@ impl DropboxReader { } impl oio::Read for DropboxReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.dropbox_get(&self.path, range, &self.op).await?; @@ -50,7 +51,7 @@ impl oio::Read for DropboxReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/fs/reader.rs b/core/src/services/fs/reader.rs index af03e80e00d3..642f2b2c8e9f 100644 --- a/core/src/services/fs/reader.rs +++ b/core/src/services/fs/reader.rs @@ -55,7 +55,7 @@ impl FsReader { } impl oio::Read for FsReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let handle = self.try_clone()?; match tokio::runtime::Handle::try_current() { @@ -74,7 +74,7 @@ impl oio::Read for FsReader { } impl oio::BlockingRead for FsReader { - fn read_at(&self, mut offset: u64, limit: usize) -> Result { + fn read_at(&self, mut offset: u64, limit: usize) -> Result { let mut bs = Vec::with_capacity(limit); let buf = bs.spare_capacity_mut(); @@ -101,6 +101,6 @@ impl oio::BlockingRead for FsReader { // Safety: We make sure that bs contains `n` more bytes. let filled = read_buf.filled().len(); unsafe { bs.set_len(filled) } - Ok(oio::Buffer::from(bs)) + Ok(Buffer::from(bs)) } } diff --git a/core/src/services/fs/writer.rs b/core/src/services/fs/writer.rs index 0332acf9d032..7ec3ce9c3736 100644 --- a/core/src/services/fs/writer.rs +++ b/core/src/services/fs/writer.rs @@ -48,7 +48,7 @@ impl FsWriter { unsafe impl Sync for FsWriter {} impl oio::Write for FsWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let f = self.f.as_mut().expect("FsWriter must be initialized"); // TODO: use write_vectored instead. @@ -83,7 +83,7 @@ impl oio::Write for FsWriter { } impl oio::BlockingWrite for FsWriter { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let f = self.f.as_mut().expect("FsWriter must be initialized"); f.write(bs.chunk()).map_err(new_std_io_error) diff --git a/core/src/services/ftp/reader.rs b/core/src/services/ftp/reader.rs index f85f7074c4fd..72cd02fb2fcf 100644 --- a/core/src/services/ftp/reader.rs +++ b/core/src/services/ftp/reader.rs @@ -40,7 +40,7 @@ impl FtpReader { } impl oio::Read for FtpReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let mut ftp_stream = self.core.ftp_connect(Operation::Read).await?; if offset != 0 { @@ -57,6 +57,6 @@ impl oio::Read for FtpReader { .take(limit as _); let mut bs = Vec::with_capacity(limit); ds.read_to_end(&mut bs).await.map_err(new_std_io_error)?; - Ok(oio::Buffer::from(bs)) + Ok(Buffer::from(bs)) } } diff --git a/core/src/services/gcs/core.rs b/core/src/services/gcs/core.rs index 491625d32276..494c387e6eb5 100644 --- a/core/src/services/gcs/core.rs +++ b/core/src/services/gcs/core.rs @@ -141,7 +141,7 @@ impl GcsCore { } #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } } @@ -212,7 +212,7 @@ impl GcsCore { path: &str, range: BytesRange, args: &OpRead, - ) -> Result> { + ) -> Result> { let mut req = self.gcs_get_object_request(path, range, args)?; self.sign(&mut req).await?; @@ -394,7 +394,7 @@ impl GcsCore { &self, path: &str, args: &OpStat, - ) -> Result> { + ) -> Result> { let mut req = self.gcs_head_object_request(path, args)?; self.sign(&mut req).await?; @@ -402,7 +402,7 @@ impl GcsCore { self.send(req).await } - pub async fn gcs_delete_object(&self, path: &str) -> Result> { + pub async fn gcs_delete_object(&self, path: &str) -> Result> { let mut req = self.gcs_delete_object_request(path)?; self.sign(&mut req).await?; @@ -424,7 +424,7 @@ impl GcsCore { .map_err(new_request_build_error) } - pub async fn gcs_delete_objects(&self, paths: Vec) -> Result> { + pub async fn gcs_delete_objects(&self, paths: Vec) -> Result> { let uri = format!("{}/batch/storage/v1", self.endpoint); let mut multipart = Multipart::new(); @@ -444,7 +444,7 @@ impl GcsCore { self.send(req).await } - pub async fn gcs_copy_object(&self, from: &str, to: &str) -> Result> { + pub async fn gcs_copy_object(&self, from: &str, to: &str) -> Result> { let source = build_abs_path(&self.root, from); let dest = build_abs_path(&self.root, to); @@ -473,7 +473,7 @@ impl GcsCore { delimiter: &str, limit: Option, start_after: Option, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let mut url = format!( @@ -514,7 +514,7 @@ impl GcsCore { self.send(req).await } - pub async fn gcs_initiate_resumable_upload(&self, path: &str) -> Result> { + pub async fn gcs_initiate_resumable_upload(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( "{}/upload/storage/v1/b/{}/o?uploadType=resumable&name={}", @@ -557,7 +557,7 @@ impl GcsCore { written: u64, size: u64, body: AsyncBody, - ) -> Result> { + ) -> Result> { let mut req = Request::post(location) .header(CONTENT_LENGTH, size) .header( @@ -577,10 +577,7 @@ impl GcsCore { self.send(req).await } - pub async fn gcs_abort_resumable_upload( - &self, - location: &str, - ) -> Result> { + pub async fn gcs_abort_resumable_upload(&self, location: &str) -> Result> { let mut req = Request::delete(location) .header(CONTENT_LENGTH, 0) .body(AsyncBody::Empty) diff --git a/core/src/services/gcs/error.rs b/core/src/services/gcs/error.rs index 38ffa0486ba4..84c5fda83aee 100644 --- a/core/src/services/gcs/error.rs +++ b/core/src/services/gcs/error.rs @@ -22,9 +22,7 @@ use serde::Deserialize; use serde_json::de; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; #[derive(Default, Debug, Deserialize)] #[serde(default, rename_all = "camelCase")] @@ -51,7 +49,7 @@ struct GcsErrorDetail { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/gcs/reader.rs b/core/src/services/gcs/reader.rs index bc10981cb2c7..88a80c048e47 100644 --- a/core/src/services/gcs/reader.rs +++ b/core/src/services/gcs/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::GcsCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct GcsReader { core: Arc, @@ -41,7 +42,7 @@ impl GcsReader { } impl oio::Read for GcsReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self @@ -53,7 +54,7 @@ impl oio::Read for GcsReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/gdrive/core.rs b/core/src/services/gdrive/core.rs index e5d34adacbf8..36921c4ca14f 100644 --- a/core/src/services/gdrive/core.rs +++ b/core/src/services/gdrive/core.rs @@ -35,9 +35,7 @@ use tokio::sync::Mutex; use super::error::parse_error; use crate::raw::*; -use crate::types::Result; -use crate::Error; -use crate::ErrorKind; +use crate::*; pub struct GdriveCore { pub root: String, @@ -59,7 +57,7 @@ impl Debug for GdriveCore { } impl GdriveCore { - pub async fn gdrive_stat(&self, path: &str) -> Result> { + pub async fn gdrive_stat(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let file_id = self.path_cache.get(&path).await?.ok_or(Error::new( ErrorKind::NotFound, @@ -79,7 +77,7 @@ impl GdriveCore { self.client.send(req).await } - pub async fn gdrive_get(&self, path: &str, range: BytesRange) -> Result> { + pub async fn gdrive_get(&self, path: &str, range: BytesRange) -> Result> { let path = build_abs_path(&self.root, path); let path_id = self.path_cache.get(&path).await?.ok_or(Error::new( ErrorKind::NotFound, @@ -105,7 +103,7 @@ impl GdriveCore { file_id: &str, page_size: i32, next_page_token: &str, - ) -> Result> { + ) -> Result> { let q = format!("'{}' in parents and trashed = false", file_id); let mut url = format!( "https://www.googleapis.com/drive/v3/files?pageSize={}&q={}", @@ -129,7 +127,7 @@ impl GdriveCore { &self, source: &str, target: &str, - ) -> Result> { + ) -> Result> { let source_file_id = self.path_cache.get(source).await?.ok_or(Error::new( ErrorKind::NotFound, &format!("source path not found: {}", source), @@ -163,7 +161,7 @@ impl GdriveCore { self.client.send(req).await } - pub async fn gdrive_trash(&self, file_id: &str) -> Result> { + pub async fn gdrive_trash(&self, file_id: &str) -> Result> { let url = format!("https://www.googleapis.com/drive/v3/files/{}", file_id); let body = serde_json::to_vec(&json!({ @@ -186,7 +184,7 @@ impl GdriveCore { path: &str, size: u64, body: Bytes, - ) -> Result> { + ) -> Result> { let parent = self.path_cache.ensure_dir(get_parent(path)).await?; let url = "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"; @@ -236,7 +234,7 @@ impl GdriveCore { file_id: &str, size: u64, body: Bytes, - ) -> Result> { + ) -> Result> { let url = format!( "https://www.googleapis.com/upload/drive/v3/files/{}?uploadType=media", file_id diff --git a/core/src/services/gdrive/error.rs b/core/src/services/gdrive/error.rs index f9e57ecef804..12a92d8f9ac7 100644 --- a/core/src/services/gdrive/error.rs +++ b/core/src/services/gdrive/error.rs @@ -21,9 +21,7 @@ use http::StatusCode; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; #[derive(Default, Debug, Deserialize)] struct GdriveError { @@ -36,7 +34,7 @@ struct GdriveInnerError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/gdrive/reader.rs b/core/src/services/gdrive/reader.rs index 267777753a84..557864d57754 100644 --- a/core/src/services/gdrive/reader.rs +++ b/core/src/services/gdrive/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::GdriveCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct GdriveReader { core: Arc, @@ -41,7 +42,7 @@ impl GdriveReader { } impl oio::Read for GdriveReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.gdrive_get(&self.path, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for GdriveReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/gdrive/writer.rs b/core/src/services/gdrive/writer.rs index 9647b55b6dad..ebd91afbdd67 100644 --- a/core/src/services/gdrive/writer.rs +++ b/core/src/services/gdrive/writer.rs @@ -17,8 +17,7 @@ use std::sync::Arc; -use bytes::Buf; -use bytes::Bytes; +use bytes::{Buf, Bytes}; use http::StatusCode; use super::core::GdriveCore; diff --git a/core/src/services/ghac/backend.rs b/core/src/services/ghac/backend.rs index 76b1349319fd..64dd6e126510 100644 --- a/core/src/services/ghac/backend.rs +++ b/core/src/services/ghac/backend.rs @@ -461,7 +461,7 @@ impl GhacBackend { Ok(req) } - async fn ghac_delete(&self, path: &str) -> Result> { + async fn ghac_delete(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/ghac/error.rs b/core/src/services/ghac/error.rs index c84004e6cd29..e58a175b66bf 100644 --- a/core/src/services/ghac/error.rs +++ b/core/src/services/ghac/error.rs @@ -20,12 +20,10 @@ use http::Response; use http::StatusCode; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let (kind, retryable) = match parts.status { diff --git a/core/src/services/ghac/reader.rs b/core/src/services/ghac/reader.rs index c6fcfea79aeb..eb1b87b28dd9 100644 --- a/core/src/services/ghac/reader.rs +++ b/core/src/services/ghac/reader.rs @@ -20,6 +20,7 @@ use http::StatusCode; use super::error::parse_error; use crate::raw::*; use crate::services::ghac::backend::GhacBackend; +use crate::*; pub struct GhacReader { core: GhacBackend, @@ -39,7 +40,7 @@ impl GhacReader { } impl oio::Read for GhacReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let req = self.core.ghac_get_location(&self.location, range).await?; @@ -49,7 +50,7 @@ impl oio::Read for GhacReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/ghac/writer.rs b/core/src/services/ghac/writer.rs index a06e38710853..b339737cf9b8 100644 --- a/core/src/services/ghac/writer.rs +++ b/core/src/services/ghac/writer.rs @@ -38,7 +38,7 @@ impl GhacWriter { } impl oio::Write for GhacWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let size = bs.len(); let offset = self.size; diff --git a/core/src/services/github/core.rs b/core/src/services/github/core.rs index 799cbe4fce18..aec6dca1c1a8 100644 --- a/core/src/services/github/core.rs +++ b/core/src/services/github/core.rs @@ -60,7 +60,7 @@ impl Debug for GithubCore { impl GithubCore { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -113,7 +113,7 @@ impl GithubCore { } } - pub async fn stat(&self, path: &str) -> Result> { + pub async fn stat(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -135,7 +135,7 @@ impl GithubCore { self.send(req).await } - pub async fn get(&self, path: &str, range: BytesRange) -> Result> { + pub async fn get(&self, path: &str, range: BytesRange) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -158,7 +158,7 @@ impl GithubCore { self.send(req).await } - pub async fn upload(&self, path: &str, bs: Bytes) -> Result> { + pub async fn upload(&self, path: &str, bs: Bytes) -> Result> { let sha = self.get_file_sha(path).await?; let path = build_abs_path(&self.root, path); diff --git a/core/src/services/github/error.rs b/core/src/services/github/error.rs index b438a82522c1..171deb7d14ec 100644 --- a/core/src/services/github/error.rs +++ b/core/src/services/github/error.rs @@ -20,9 +20,7 @@ use http::Response; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; #[derive(Default, Debug, Deserialize)] #[allow(dead_code)] @@ -38,7 +36,7 @@ struct GithubSubError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -92,7 +90,7 @@ mod test { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/github/reader.rs b/core/src/services/github/reader.rs index 64fd0ded58a6..6c0276208151 100644 --- a/core/src/services/github/reader.rs +++ b/core/src/services/github/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::GithubCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct GithubReader { core: Arc, @@ -41,7 +42,7 @@ impl GithubReader { } impl oio::Read for GithubReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.get(&self.path, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for GithubReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/hdfs/reader.rs b/core/src/services/hdfs/reader.rs index 63b17a05587c..ceb563e18dac 100644 --- a/core/src/services/hdfs/reader.rs +++ b/core/src/services/hdfs/reader.rs @@ -21,8 +21,7 @@ use hdrs::File; use tokio::io::ReadBuf; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; +use crate::*; pub struct HdfsReader { f: Arc, @@ -35,7 +34,7 @@ impl HdfsReader { } impl oio::Read for HdfsReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let r = Self { f: self.f.clone() }; match tokio::runtime::Handle::try_current() { Ok(runtime) => runtime @@ -53,7 +52,7 @@ impl oio::Read for HdfsReader { } impl oio::BlockingRead for HdfsReader { - fn read_at(&self, mut offset: u64, limit: usize) -> crate::Result { + fn read_at(&self, mut offset: u64, limit: usize) -> Result { let mut bs = Vec::with_capacity(limit); let buf = bs.spare_capacity_mut(); @@ -83,6 +82,6 @@ impl oio::BlockingRead for HdfsReader { // Safety: We make sure that bs contains `n` more bytes. let filled = read_buf.filled().len(); unsafe { bs.set_len(filled) } - Ok(oio::Buffer::from(bs)) + Ok(Buffer::from(bs)) } } diff --git a/core/src/services/hdfs/writer.rs b/core/src/services/hdfs/writer.rs index a72cc26c49b1..277ad0e3e89b 100644 --- a/core/src/services/hdfs/writer.rs +++ b/core/src/services/hdfs/writer.rs @@ -53,7 +53,7 @@ impl HdfsWriter { } impl oio::Write for HdfsWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { let f = self.f.as_mut().expect("HdfsWriter must be initialized"); f.write(bs.chunk()).await.map_err(new_std_io_error) @@ -82,7 +82,7 @@ impl oio::Write for HdfsWriter { } impl oio::BlockingWrite for HdfsWriter { - fn write(&mut self, bs: oio::Buffer) -> Result { + fn write(&mut self, bs: Buffer) -> Result { let f = self.f.as_mut().expect("HdfsWriter must be initialized"); f.write(bs.chunk()).map_err(new_std_io_error) } diff --git a/core/src/services/hdfs_native/reader.rs b/core/src/services/hdfs_native/reader.rs index f54697236604..1554af2bcd6c 100644 --- a/core/src/services/hdfs_native/reader.rs +++ b/core/src/services/hdfs_native/reader.rs @@ -17,7 +17,8 @@ use hdfs_native::file::FileReader; -use crate::raw::oio; +use crate::raw::*; +use crate::*; pub struct HdfsNativeReader { _f: FileReader, @@ -30,7 +31,7 @@ impl HdfsNativeReader { } impl oio::Read for HdfsNativeReader { - async fn read_at(&self, _offset: u64, _limit: usize) -> crate::Result { + async fn read_at(&self, _offset: u64, _limit: usize) -> Result { todo!() } } diff --git a/core/src/services/hdfs_native/writer.rs b/core/src/services/hdfs_native/writer.rs index 888e9c7d4379..e6fb0205e4f2 100644 --- a/core/src/services/hdfs_native/writer.rs +++ b/core/src/services/hdfs_native/writer.rs @@ -31,7 +31,7 @@ impl HdfsNativeWriter { } impl oio::Write for HdfsNativeWriter { - async fn write(&mut self, _bs: oio::Buffer) -> Result { + async fn write(&mut self, _bs: Buffer) -> Result { todo!() } diff --git a/core/src/services/http/backend.rs b/core/src/services/http/backend.rs index 5028d99b731e..2ad3e445e7f1 100644 --- a/core/src/services/http/backend.rs +++ b/core/src/services/http/backend.rs @@ -284,7 +284,7 @@ impl HttpBackend { path: &str, range: BytesRange, args: &OpRead, - ) -> Result> { + ) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&p)); @@ -314,7 +314,7 @@ impl HttpBackend { self.client.send(req).await } - async fn http_head(&self, path: &str, args: &OpStat) -> Result> { + async fn http_head(&self, path: &str, args: &OpStat) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&p)); diff --git a/core/src/services/http/error.rs b/core/src/services/http/error.rs index 451f89d10cd1..573b3412b317 100644 --- a/core/src/services/http/error.rs +++ b/core/src/services/http/error.rs @@ -20,12 +20,10 @@ use http::Response; use http::StatusCode; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/http/reader.rs b/core/src/services/http/reader.rs index d38dc4b2a2cf..204babe69848 100644 --- a/core/src/services/http/reader.rs +++ b/core/src/services/http/reader.rs @@ -20,6 +20,7 @@ use http::StatusCode; use super::error::parse_error; use crate::raw::*; use crate::services::http::backend::HttpBackend; +use crate::*; pub struct HttpReader { core: HttpBackend, @@ -39,7 +40,7 @@ impl HttpReader { } impl oio::Read for HttpReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.http_get(&self.path, range, &self.op).await?; @@ -48,7 +49,7 @@ impl oio::Read for HttpReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/huggingface/core.rs b/core/src/services/huggingface/core.rs index ed9d271c160b..b9461bad9156 100644 --- a/core/src/services/huggingface/core.rs +++ b/core/src/services/huggingface/core.rs @@ -49,7 +49,7 @@ impl Debug for HuggingfaceCore { } impl HuggingfaceCore { - pub async fn hf_path_info(&self, path: &str) -> Result> { + pub async fn hf_path_info(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); @@ -83,7 +83,7 @@ impl HuggingfaceCore { self.client.send(req).await } - pub async fn hf_list(&self, path: &str, recursive: bool) -> Result> { + pub async fn hf_list(&self, path: &str, recursive: bool) -> Result> { let p = build_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); @@ -126,7 +126,7 @@ impl HuggingfaceCore { path: &str, range: BytesRange, _args: &OpRead, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); diff --git a/core/src/services/huggingface/error.rs b/core/src/services/huggingface/error.rs index c17cd2ee0d3f..a77a5aadfb5e 100644 --- a/core/src/services/huggingface/error.rs +++ b/core/src/services/huggingface/error.rs @@ -40,7 +40,7 @@ impl Debug for HuggingfaceError { } } -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/huggingface/reader.rs b/core/src/services/huggingface/reader.rs index d7caca047748..371b362a07e7 100644 --- a/core/src/services/huggingface/reader.rs +++ b/core/src/services/huggingface/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::HuggingfaceCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct HuggingfaceReader { core: Arc, @@ -41,7 +42,7 @@ impl HuggingfaceReader { } impl oio::Read for HuggingfaceReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.hf_resolve(&self.path, range, &self.op).await?; @@ -50,7 +51,7 @@ impl oio::Read for HuggingfaceReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/icloud/core.rs b/core/src/services/icloud/core.rs index 26c2aed890d9..956a3445560a 100644 --- a/core/src/services/icloud/core.rs +++ b/core/src/services/icloud/core.rs @@ -275,7 +275,7 @@ impl IcloudSigner { } /// Update signer's data after request sent out. - fn update(&mut self, resp: &Response) -> Result<()> { + fn update(&mut self, resp: &Response) -> Result<()> { if let Some(account_country) = parse_header_to_str(resp.headers(), ACCOUNT_COUNTRY_HEADER)? { self.data.account_country = Some(account_country.to_string()); @@ -312,7 +312,7 @@ impl IcloudSigner { /// - Init the signer if it's not initiated. /// - Sign the request. /// - Update the session data if needed. - pub async fn send(&mut self, mut req: Request) -> Result> { + pub async fn send(&mut self, mut req: Request) -> Result> { self.sign(&mut req)?; let resp = self.client.send(req).await?; @@ -374,7 +374,7 @@ impl IcloudCore { zone: &str, range: BytesRange, args: OpRead, - ) -> Result> { + ) -> Result> { let mut signer = self.signer.lock().await; let uri = format!( @@ -426,7 +426,7 @@ impl IcloudCore { path: &str, range: BytesRange, args: &OpRead, - ) -> Result> { + ) -> Result> { let path = build_rooted_abs_path(&self.root, path); let base = get_basename(&path); @@ -572,7 +572,7 @@ impl PathQuery for IcloudPathQuery { } } -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/icloud/reader.rs b/core/src/services/icloud/reader.rs index f001cb001a78..281e9aca0390 100644 --- a/core/src/services/icloud/reader.rs +++ b/core/src/services/icloud/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::parse_error; use super::core::IcloudCore; use crate::raw::*; +use crate::*; pub struct IcloudReader { core: Arc, @@ -41,7 +42,7 @@ impl IcloudReader { } impl oio::Read for IcloudReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.read(&self.path, range, &self.op).await?; @@ -50,7 +51,7 @@ impl oio::Read for IcloudReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/ipfs/backend.rs b/core/src/services/ipfs/backend.rs index d489832174b7..556d62881ed4 100644 --- a/core/src/services/ipfs/backend.rs +++ b/core/src/services/ipfs/backend.rs @@ -348,7 +348,7 @@ impl Accessor for IpfsBackend { } impl IpfsBackend { - pub async fn ipfs_get(&self, path: &str, range: BytesRange) -> Result> { + pub async fn ipfs_get(&self, path: &str, range: BytesRange) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&p)); @@ -366,7 +366,7 @@ impl IpfsBackend { self.client.send(req).await } - async fn ipfs_head(&self, path: &str) -> Result> { + async fn ipfs_head(&self, path: &str) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&p)); @@ -380,7 +380,7 @@ impl IpfsBackend { self.client.send(req).await } - async fn ipfs_list(&self, path: &str) -> Result> { + async fn ipfs_list(&self, path: &str) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&p)); diff --git a/core/src/services/ipfs/error.rs b/core/src/services/ipfs/error.rs index 99177e9b388c..777886ce8e03 100644 --- a/core/src/services/ipfs/error.rs +++ b/core/src/services/ipfs/error.rs @@ -20,12 +20,10 @@ use http::Response; use http::StatusCode; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/ipfs/reader.rs b/core/src/services/ipfs/reader.rs index 75b1cd1c197b..064a20b62c36 100644 --- a/core/src/services/ipfs/reader.rs +++ b/core/src/services/ipfs/reader.rs @@ -20,6 +20,7 @@ use http::StatusCode; use super::error::parse_error; use crate::raw::*; use crate::services::ipfs::backend::IpfsBackend; +use crate::*; pub struct IpfsReader { core: IpfsBackend, @@ -39,7 +40,7 @@ impl IpfsReader { } impl oio::Read for IpfsReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.ipfs_get(&self.path, range).await?; @@ -48,7 +49,7 @@ impl oio::Read for IpfsReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/ipmfs/backend.rs b/core/src/services/ipmfs/backend.rs index 7a5674d8d31c..e21d6646e956 100644 --- a/core/src/services/ipmfs/backend.rs +++ b/core/src/services/ipmfs/backend.rs @@ -167,7 +167,7 @@ impl Accessor for IpmfsBackend { } impl IpmfsBackend { - async fn ipmfs_stat(&self, path: &str) -> Result> { + async fn ipmfs_stat(&self, path: &str) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!( @@ -184,7 +184,7 @@ impl IpmfsBackend { self.client.send(req).await } - pub async fn ipmfs_read(&self, path: &str, range: BytesRange) -> Result> { + pub async fn ipmfs_read(&self, path: &str, range: BytesRange) -> Result> { let p = build_rooted_abs_path(&self.root, path); let mut url = format!( @@ -206,7 +206,7 @@ impl IpmfsBackend { self.client.send(req).await } - async fn ipmfs_rm(&self, path: &str) -> Result> { + async fn ipmfs_rm(&self, path: &str) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!( @@ -223,7 +223,7 @@ impl IpmfsBackend { self.client.send(req).await } - pub(crate) async fn ipmfs_ls(&self, path: &str) -> Result> { + pub(crate) async fn ipmfs_ls(&self, path: &str) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!( @@ -240,7 +240,7 @@ impl IpmfsBackend { self.client.send(req).await } - async fn ipmfs_mkdir(&self, path: &str) -> Result> { + async fn ipmfs_mkdir(&self, path: &str) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!( @@ -258,7 +258,7 @@ impl IpmfsBackend { } /// Support write from reader. - pub async fn ipmfs_write(&self, path: &str, body: Bytes) -> Result> { + pub async fn ipmfs_write(&self, path: &str, body: Bytes) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/ipmfs/error.rs b/core/src/services/ipmfs/error.rs index ee07566e1bdf..32de94b0d47e 100644 --- a/core/src/services/ipmfs/error.rs +++ b/core/src/services/ipmfs/error.rs @@ -22,9 +22,7 @@ use serde::Deserialize; use serde_json::de; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; #[derive(Deserialize, Default, Debug)] #[serde(default)] @@ -46,7 +44,7 @@ struct IpfsError { /// > (if no error, check the daemon logs). /// /// ref: https://docs.ipfs.tech/reference/kubo/rpc/#http-status-codes -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/ipmfs/reader.rs b/core/src/services/ipmfs/reader.rs index 3aaac81a3e7d..ee802afbe8c5 100644 --- a/core/src/services/ipmfs/reader.rs +++ b/core/src/services/ipmfs/reader.rs @@ -20,6 +20,7 @@ use http::StatusCode; use super::error::parse_error; use crate::raw::*; use crate::services::ipmfs::backend::IpmfsBackend; +use crate::*; pub struct IpmfsReader { core: IpmfsBackend, @@ -39,7 +40,7 @@ impl IpmfsReader { } impl oio::Read for IpmfsReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.ipmfs_read(&self.path, range).await?; @@ -48,7 +49,7 @@ impl oio::Read for IpmfsReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/koofr/core.rs b/core/src/services/koofr/core.rs index dc6372d2cae9..2b59479bfa8d 100644 --- a/core/src/services/koofr/core.rs +++ b/core/src/services/koofr/core.rs @@ -68,7 +68,7 @@ impl Debug for KoofrCore { impl KoofrCore { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -221,7 +221,7 @@ impl KoofrCore { } } - pub async fn info(&self, path: &str) -> Result> { + pub async fn info(&self, path: &str) -> Result> { let mount_id = self.get_mount_id().await?; let url = format!( @@ -242,7 +242,7 @@ impl KoofrCore { self.send(req).await } - pub async fn get(&self, path: &str, range: BytesRange) -> Result> { + pub async fn get(&self, path: &str, range: BytesRange) -> Result> { let path = build_rooted_abs_path(&self.root, path); let mount_id = self.get_mount_id().await?; @@ -265,7 +265,7 @@ impl KoofrCore { self.send(req).await } - pub async fn put(&self, path: &str, bs: Bytes) -> Result> { + pub async fn put(&self, path: &str, bs: Bytes) -> Result> { let path = build_rooted_abs_path(&self.root, path); let filename = get_basename(&path); @@ -301,7 +301,7 @@ impl KoofrCore { self.send(req).await } - pub async fn remove(&self, path: &str) -> Result> { + pub async fn remove(&self, path: &str) -> Result> { let path = build_rooted_abs_path(&self.root, path); let mount_id = self.get_mount_id().await?; @@ -324,7 +324,7 @@ impl KoofrCore { self.send(req).await } - pub async fn copy(&self, from: &str, to: &str) -> Result> { + pub async fn copy(&self, from: &str, to: &str) -> Result> { let from = build_rooted_abs_path(&self.root, from); let to = build_rooted_abs_path(&self.root, to); @@ -356,7 +356,7 @@ impl KoofrCore { self.send(req).await } - pub async fn move_object(&self, from: &str, to: &str) -> Result> { + pub async fn move_object(&self, from: &str, to: &str) -> Result> { let from = build_rooted_abs_path(&self.root, from); let to = build_rooted_abs_path(&self.root, to); @@ -388,7 +388,7 @@ impl KoofrCore { self.send(req).await } - pub async fn list(&self, path: &str) -> Result> { + pub async fn list(&self, path: &str) -> Result> { let path = build_rooted_abs_path(&self.root, path); let mount_id = self.get_mount_id().await?; diff --git a/core/src/services/koofr/error.rs b/core/src/services/koofr/error.rs index d3ee3ff3ae8c..0ae780159125 100644 --- a/core/src/services/koofr/error.rs +++ b/core/src/services/koofr/error.rs @@ -19,12 +19,10 @@ use bytes::Buf; use http::Response; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -64,7 +62,7 @@ mod test { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/koofr/reader.rs b/core/src/services/koofr/reader.rs index 94c48ea93b20..7f7f65c4d4e5 100644 --- a/core/src/services/koofr/reader.rs +++ b/core/src/services/koofr/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::KoofrCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct KoofrReader { core: Arc, @@ -41,7 +42,7 @@ impl KoofrReader { } impl oio::Read for KoofrReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.get(&self.path, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for KoofrReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/libsql/error.rs b/core/src/services/libsql/error.rs index 59804a6e4fd5..baeeb2c97c3b 100644 --- a/core/src/services/libsql/error.rs +++ b/core/src/services/libsql/error.rs @@ -20,12 +20,10 @@ use http::Response; use http::StatusCode; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/obs/core.rs b/core/src/services/obs/core.rs index ca01ee4135c5..c57d32d4294c 100644 --- a/core/src/services/obs/core.rs +++ b/core/src/services/obs/core.rs @@ -95,7 +95,7 @@ impl ObsCore { } #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } } @@ -106,7 +106,7 @@ impl ObsCore { path: &str, range: BytesRange, args: &OpRead, - ) -> Result> { + ) -> Result> { let mut req = self.obs_get_object_request(path, range, args)?; self.sign(&mut req).await?; @@ -174,11 +174,7 @@ impl ObsCore { Ok(req) } - pub async fn obs_head_object( - &self, - path: &str, - args: &OpStat, - ) -> Result> { + pub async fn obs_head_object(&self, path: &str, args: &OpStat) -> Result> { let mut req = self.obs_head_object_request(path, args)?; self.sign(&mut req).await?; @@ -211,7 +207,7 @@ impl ObsCore { Ok(req) } - pub async fn obs_delete_object(&self, path: &str) -> Result> { + pub async fn obs_delete_object(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!("{}/{}", self.endpoint, percent_encode_path(&p)); @@ -263,7 +259,7 @@ impl ObsCore { Ok(req) } - pub async fn obs_copy_object(&self, from: &str, to: &str) -> Result> { + pub async fn obs_copy_object(&self, from: &str, to: &str) -> Result> { let source = build_abs_path(&self.root, from); let target = build_abs_path(&self.root, to); @@ -286,7 +282,7 @@ impl ObsCore { next_marker: &str, delimiter: &str, limit: Option, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let mut queries = vec![]; @@ -321,7 +317,7 @@ impl ObsCore { &self, path: &str, content_type: Option<&str>, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!("{}/{}?uploads", self.endpoint, percent_encode_path(&p)); @@ -345,7 +341,7 @@ impl ObsCore { part_number: usize, size: Option, body: AsyncBody, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -375,7 +371,7 @@ impl ObsCore { path: &str, upload_id: &str, parts: Vec, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( "{}/{}?uploadId={}", @@ -408,7 +404,7 @@ impl ObsCore { &self, path: &str, upload_id: &str, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/obs/error.rs b/core/src/services/obs/error.rs index 034def4d2aa4..8975763556a9 100644 --- a/core/src/services/obs/error.rs +++ b/core/src/services/obs/error.rs @@ -22,9 +22,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// ObsError is the error returned by obs service. #[derive(Default, Debug, Deserialize)] @@ -38,7 +36,7 @@ struct ObsError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/obs/reader.rs b/core/src/services/obs/reader.rs index fb220e2eeb9d..b85290d893ce 100644 --- a/core/src/services/obs/reader.rs +++ b/core/src/services/obs/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::ObsCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct ObsReader { core: Arc, @@ -41,7 +42,7 @@ impl ObsReader { } impl oio::Read for ObsReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self @@ -53,7 +54,7 @@ impl oio::Read for ObsReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/onedrive/backend.rs b/core/src/services/onedrive/backend.rs index 40f26967d044..0035aa7154fa 100644 --- a/core/src/services/onedrive/backend.rs +++ b/core/src/services/onedrive/backend.rs @@ -190,7 +190,7 @@ impl Accessor for OnedriveBackend { impl OnedriveBackend { pub(crate) const BASE_URL: &'static str = "https://graph.microsoft.com/v1.0/me"; - async fn onedrive_get_stat(&self, path: &str) -> Result> { + async fn onedrive_get_stat(&self, path: &str) -> Result> { let path = build_rooted_abs_path(&self.root, path); let url: String = format!( "https://graph.microsoft.com/v1.0/me/drive/root:{}{}", @@ -210,10 +210,7 @@ impl OnedriveBackend { self.client.send(req).await } - pub(crate) async fn onedrive_get_next_list_page( - &self, - url: &str, - ) -> Result> { + pub(crate) async fn onedrive_get_next_list_page(&self, url: &str) -> Result> { let mut req = Request::get(url); let auth_header_content = format!("Bearer {}", self.access_token); @@ -230,7 +227,7 @@ impl OnedriveBackend { &self, path: &str, range: BytesRange, - ) -> Result> { + ) -> Result> { let path = build_rooted_abs_path(&self.root, path); let url: String = format!( "https://graph.microsoft.com/v1.0/me/drive/root:{}{}", @@ -256,7 +253,7 @@ impl OnedriveBackend { size: Option, args: &OpWrite, body: AsyncBody, - ) -> Result> { + ) -> Result> { let url = format!( "https://graph.microsoft.com/v1.0/me/drive/root:{}:/content", percent_encode_path(path) @@ -288,7 +285,7 @@ impl OnedriveBackend { chunk_end: usize, total_len: usize, body: AsyncBody, - ) -> Result> { + ) -> Result> { let mut req = Request::put(url); let auth_header_content = format!("Bearer {}", self.access_token); @@ -313,7 +310,7 @@ impl OnedriveBackend { &self, url: &str, body: OneDriveUploadSessionCreationRequestBody, - ) -> Result> { + ) -> Result> { let mut req = Request::post(url); let auth_header_content = format!("Bearer {}", self.access_token); @@ -332,7 +329,7 @@ impl OnedriveBackend { &self, url: &str, body: CreateDirPayload, - ) -> Result> { + ) -> Result> { let mut req = Request::post(url); let auth_header_content = format!("Bearer {}", self.access_token); @@ -346,7 +343,7 @@ impl OnedriveBackend { self.client.send(req).await } - pub(crate) async fn onedrive_delete(&self, path: &str) -> Result> { + pub(crate) async fn onedrive_delete(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( "https://graph.microsoft.com/v1.0/me/drive/root:/{}", diff --git a/core/src/services/onedrive/error.rs b/core/src/services/onedrive/error.rs index 30a90f7a4f92..89724c826be2 100644 --- a/core/src/services/onedrive/error.rs +++ b/core/src/services/onedrive/error.rs @@ -20,12 +20,10 @@ use http::Response; use http::StatusCode; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/onedrive/reader.rs b/core/src/services/onedrive/reader.rs index 355789936a7d..42b4ee366132 100644 --- a/core/src/services/onedrive/reader.rs +++ b/core/src/services/onedrive/reader.rs @@ -20,6 +20,7 @@ use http::StatusCode; use super::error::parse_error; use crate::raw::*; use crate::services::onedrive::backend::OnedriveBackend; +use crate::*; pub struct OnedriveReader { core: OnedriveBackend, @@ -39,7 +40,7 @@ impl OnedriveReader { } impl oio::Read for OnedriveReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.onedrive_get_content(&self.path, range).await?; @@ -48,7 +49,7 @@ impl oio::Read for OnedriveReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs index 6d3924ab68b7..cc2a1760547c 100644 --- a/core/src/services/oss/core.rs +++ b/core/src/services/oss/core.rs @@ -126,7 +126,7 @@ impl OssCore { } #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -369,7 +369,7 @@ impl OssCore { path: &str, range: BytesRange, args: &OpRead, - ) -> Result> { + ) -> Result> { let mut req = self.oss_get_object_request(path, range, false, args)?; self.sign(&mut req).await?; self.send(req).await @@ -380,7 +380,7 @@ impl OssCore { path: &str, if_match: Option<&str>, if_none_match: Option<&str>, - ) -> Result> { + ) -> Result> { let mut req = self.oss_head_object_request(path, false, if_match, if_none_match)?; self.sign(&mut req).await?; @@ -393,14 +393,14 @@ impl OssCore { size: Option, args: &OpWrite, body: AsyncBody, - ) -> Result> { + ) -> Result> { let mut req = self.oss_put_object_request(path, size, args, body, false)?; self.sign(&mut req).await?; self.send(req).await } - pub async fn oss_copy_object(&self, from: &str, to: &str) -> Result> { + pub async fn oss_copy_object(&self, from: &str, to: &str) -> Result> { let source = build_abs_path(&self.root, from); let target = build_abs_path(&self.root, to); @@ -432,20 +432,20 @@ impl OssCore { delimiter: &str, limit: Option, start_after: Option, - ) -> Result> { + ) -> Result> { let mut req = self.oss_list_object_request(path, token, delimiter, limit, start_after)?; self.sign(&mut req).await?; self.send(req).await } - pub async fn oss_delete_object(&self, path: &str) -> Result> { + pub async fn oss_delete_object(&self, path: &str) -> Result> { let mut req = self.oss_delete_object_request(path)?; self.sign(&mut req).await?; self.send(req).await } - pub async fn oss_delete_objects(&self, paths: Vec) -> Result> { + pub async fn oss_delete_objects(&self, paths: Vec) -> Result> { let url = format!("{}/?delete", self.endpoint); let req = Request::post(&url); @@ -491,7 +491,7 @@ impl OssCore { content_disposition: Option<&str>, cache_control: Option<&str>, is_presign: bool, - ) -> Result> { + ) -> Result> { let path = build_abs_path(&self.root, path); let endpoint = self.get_endpoint(is_presign); let url = format!("{}/{}?uploads", endpoint, percent_encode_path(&path)); @@ -522,7 +522,7 @@ impl OssCore { is_presign: bool, size: u64, body: AsyncBody, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let endpoint = self.get_endpoint(is_presign); @@ -547,7 +547,7 @@ impl OssCore { upload_id: &str, is_presign: bool, parts: Vec, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let endpoint = self.get_endpoint(is_presign); let url = format!( @@ -582,7 +582,7 @@ impl OssCore { &self, path: &str, upload_id: &str, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/oss/error.rs b/core/src/services/oss/error.rs index e1d8fcf2a200..00451ce4a051 100644 --- a/core/src/services/oss/error.rs +++ b/core/src/services/oss/error.rs @@ -22,9 +22,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// OssError is the error returned by oss service. #[derive(Default, Debug, Deserialize)] @@ -37,7 +35,7 @@ struct OssError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/oss/reader.rs b/core/src/services/oss/reader.rs index 4efb4f6dfe96..108958e397a7 100644 --- a/core/src/services/oss/reader.rs +++ b/core/src/services/oss/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::OssCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct OssReader { core: Arc, @@ -41,7 +42,7 @@ impl OssReader { } impl oio::Read for OssReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self @@ -53,7 +54,7 @@ impl oio::Read for OssReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/pcloud/core.rs b/core/src/services/pcloud/core.rs index 9bdaaa5c6f45..3573e98df128 100644 --- a/core/src/services/pcloud/core.rs +++ b/core/src/services/pcloud/core.rs @@ -57,7 +57,7 @@ impl Debug for PcloudCore { impl PcloudCore { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } } @@ -110,7 +110,7 @@ impl PcloudCore { } } - pub async fn download(&self, url: &str, range: BytesRange) -> Result> { + pub async fn download(&self, url: &str, range: BytesRange) -> Result> { let req = Request::get(url); // set body @@ -156,7 +156,7 @@ impl PcloudCore { Ok(()) } - pub async fn create_folder_if_not_exists(&self, path: &str) -> Result> { + pub async fn create_folder_if_not_exists(&self, path: &str) -> Result> { let url = format!( "{}/createfolderifnotexists?path=/{}&username={}&password={}", self.endpoint, @@ -175,7 +175,7 @@ impl PcloudCore { self.send(req).await } - pub async fn rename_file(&self, from: &str, to: &str) -> Result> { + pub async fn rename_file(&self, from: &str, to: &str) -> Result> { let from = build_abs_path(&self.root, from); let to = build_abs_path(&self.root, to); @@ -198,7 +198,7 @@ impl PcloudCore { self.send(req).await } - pub async fn rename_folder(&self, from: &str, to: &str) -> Result> { + pub async fn rename_folder(&self, from: &str, to: &str) -> Result> { let from = build_abs_path(&self.root, from); let to = build_abs_path(&self.root, to); let url = format!( @@ -220,7 +220,7 @@ impl PcloudCore { self.send(req).await } - pub async fn delete_folder(&self, path: &str) -> Result> { + pub async fn delete_folder(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -241,7 +241,7 @@ impl PcloudCore { self.send(req).await } - pub async fn delete_file(&self, path: &str) -> Result> { + pub async fn delete_file(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -262,7 +262,7 @@ impl PcloudCore { self.send(req).await } - pub async fn copy_file(&self, from: &str, to: &str) -> Result> { + pub async fn copy_file(&self, from: &str, to: &str) -> Result> { let from = build_abs_path(&self.root, from); let to = build_abs_path(&self.root, to); @@ -285,7 +285,7 @@ impl PcloudCore { self.send(req).await } - pub async fn copy_folder(&self, from: &str, to: &str) -> Result> { + pub async fn copy_folder(&self, from: &str, to: &str) -> Result> { let from = build_abs_path(&self.root, from); let to = build_abs_path(&self.root, to); @@ -308,7 +308,7 @@ impl PcloudCore { self.send(req).await } - pub async fn stat(&self, path: &str) -> Result> { + pub async fn stat(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let path = path.trim_end_matches('/'); @@ -331,7 +331,7 @@ impl PcloudCore { self.send(req).await } - pub async fn upload_file(&self, path: &str, bs: Bytes) -> Result> { + pub async fn upload_file(&self, path: &str, bs: Bytes) -> Result> { let path = build_abs_path(&self.root, path); let (name, path) = (get_basename(&path), get_parent(&path).trim_end_matches('/')); @@ -355,7 +355,7 @@ impl PcloudCore { self.send(req).await } - pub async fn list_folder(&self, path: &str) -> Result> { + pub async fn list_folder(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let path = normalize_root(&path); diff --git a/core/src/services/pcloud/error.rs b/core/src/services/pcloud/error.rs index 2f840969101e..58d3772726ee 100644 --- a/core/src/services/pcloud/error.rs +++ b/core/src/services/pcloud/error.rs @@ -23,9 +23,7 @@ use http::Response; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// PcloudError is the error returned by Pcloud service. #[derive(Default, Deserialize)] @@ -44,7 +42,7 @@ impl Debug for PcloudError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); let message = String::from_utf8_lossy(&bs).into_owned(); @@ -80,7 +78,7 @@ mod test { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/pcloud/reader.rs b/core/src/services/pcloud/reader.rs index 317073a670c7..848dfa9d0a69 100644 --- a/core/src/services/pcloud/reader.rs +++ b/core/src/services/pcloud/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::PcloudCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct PcloudReader { core: Arc, @@ -41,7 +42,7 @@ impl PcloudReader { } impl oio::Read for PcloudReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.download(&self.link, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for PcloudReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/s3/core.rs b/core/src/services/s3/core.rs index 4f93f08fea37..3c3dd33ef609 100644 --- a/core/src/services/s3/core.rs +++ b/core/src/services/s3/core.rs @@ -182,7 +182,7 @@ impl S3Core { } #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -367,7 +367,7 @@ impl S3Core { path: &str, range: BytesRange, args: &OpRead, - ) -> Result> { + ) -> Result> { let mut req = self.s3_get_object_request(path, range, args)?; self.sign(&mut req).await?; @@ -418,7 +418,7 @@ impl S3Core { Ok(req) } - pub async fn s3_head_object(&self, path: &str, args: OpStat) -> Result> { + pub async fn s3_head_object(&self, path: &str, args: OpStat) -> Result> { let mut req = self.s3_head_object_request(path, args)?; self.sign(&mut req).await?; @@ -426,7 +426,7 @@ impl S3Core { self.send(req).await } - pub async fn s3_delete_object(&self, path: &str) -> Result> { + pub async fn s3_delete_object(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!("{}/{}", self.endpoint, percent_encode_path(&p)); @@ -440,7 +440,7 @@ impl S3Core { self.send(req).await } - pub async fn s3_copy_object(&self, from: &str, to: &str) -> Result> { + pub async fn s3_copy_object(&self, from: &str, to: &str) -> Result> { let from = build_abs_path(&self.root, from); let to = build_abs_path(&self.root, to); @@ -505,7 +505,7 @@ impl S3Core { delimiter: &str, limit: Option, start_after: Option, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let mut url = format!("{}?list-type=2", self.endpoint); @@ -550,7 +550,7 @@ impl S3Core { &self, path: &str, args: &OpWrite, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!("{}/{}?uploads", self.endpoint, percent_encode_path(&p)); @@ -622,7 +622,7 @@ impl S3Core { path: &str, upload_id: &str, parts: Vec, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -658,7 +658,7 @@ impl S3Core { &self, path: &str, upload_id: &str, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -675,7 +675,7 @@ impl S3Core { self.send(req).await } - pub async fn s3_delete_objects(&self, paths: Vec) -> Result> { + pub async fn s3_delete_objects(&self, paths: Vec) -> Result> { let url = format!("{}/?delete", self.endpoint); let req = Request::post(&url); diff --git a/core/src/services/s3/error.rs b/core/src/services/s3/error.rs index 388324b9efe5..079789ef0124 100644 --- a/core/src/services/s3/error.rs +++ b/core/src/services/s3/error.rs @@ -21,9 +21,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// S3Error is the error returned by s3 service. #[derive(Default, Debug, Deserialize)] @@ -36,7 +34,7 @@ struct S3Error { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/s3/reader.rs b/core/src/services/s3/reader.rs index 91edf6f43d03..f5a83ea2bde9 100644 --- a/core/src/services/s3/reader.rs +++ b/core/src/services/s3/reader.rs @@ -42,7 +42,7 @@ impl S3Reader { } impl oio::Read for S3Reader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.s3_get_object(&self.path, range, &self.op).await?; @@ -50,7 +50,7 @@ impl oio::Read for S3Reader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/seafile/core.rs b/core/src/services/seafile/core.rs index 69fc94f3d562..f5549b870aa4 100644 --- a/core/src/services/seafile/core.rs +++ b/core/src/services/seafile/core.rs @@ -65,7 +65,7 @@ impl Debug for SeafileCore { impl SeafileCore { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -218,11 +218,7 @@ impl SeafileCore { } /// download file - pub async fn download_file( - &self, - path: &str, - range: BytesRange, - ) -> Result> { + pub async fn download_file(&self, path: &str, range: BytesRange) -> Result> { let download_url = self.get_download_url(path).await?; let req = Request::get(download_url); diff --git a/core/src/services/seafile/error.rs b/core/src/services/seafile/error.rs index 1a9a4d5537cb..c58b3c5d6202 100644 --- a/core/src/services/seafile/error.rs +++ b/core/src/services/seafile/error.rs @@ -20,9 +20,7 @@ use http::Response; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// the error response of seafile #[derive(Default, Debug, Deserialize)] @@ -32,7 +30,7 @@ struct SeafileError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -78,7 +76,7 @@ mod test { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/seafile/reader.rs b/core/src/services/seafile/reader.rs index 8db38dba88d5..b28e48e6260c 100644 --- a/core/src/services/seafile/reader.rs +++ b/core/src/services/seafile/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::SeafileCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct SeafileReader { core: Arc, @@ -41,7 +42,7 @@ impl SeafileReader { } impl oio::Read for SeafileReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.download_file(&self.path, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for SeafileReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/sftp/reader.rs b/core/src/services/sftp/reader.rs index 00e85b2cd62d..05ee2fdd997a 100644 --- a/core/src/services/sftp/reader.rs +++ b/core/src/services/sftp/reader.rs @@ -38,7 +38,7 @@ impl SftpReader { } impl oio::Read for SftpReader { - async fn read_at(&self, offset: u64, limit: usize) -> Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let client = self.inner.connect().await?; let mut fs = client.fs(); @@ -60,7 +60,7 @@ impl oio::Read for SftpReader { let mut size = limit; if size == 0 { - return Ok(oio::Buffer::new()); + return Ok(Buffer::new()); } let mut buf = BytesMut::with_capacity(limit); @@ -77,6 +77,6 @@ impl oio::Read for SftpReader { break; } } - Ok(oio::Buffer::from(buf.freeze())) + Ok(Buffer::from(buf.freeze())) } } diff --git a/core/src/services/sftp/writer.rs b/core/src/services/sftp/writer.rs index e8bc721818a0..d31e0e2ef485 100644 --- a/core/src/services/sftp/writer.rs +++ b/core/src/services/sftp/writer.rs @@ -39,7 +39,7 @@ impl SftpWriter { } impl oio::Write for SftpWriter { - async fn write(&mut self, bs: oio::Buffer) -> Result { + async fn write(&mut self, bs: Buffer) -> Result { self.file.write(bs.chunk()).await.map_err(new_std_io_error) } diff --git a/core/src/services/supabase/core.rs b/core/src/services/supabase/core.rs index 628af9e601b4..3a508f08534d 100644 --- a/core/src/services/supabase/core.rs +++ b/core/src/services/supabase/core.rs @@ -221,7 +221,7 @@ impl SupabaseCore { // core utils impl SupabaseCore { - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.http_client.send(req).await } @@ -229,7 +229,7 @@ impl SupabaseCore { &self, path: &str, range: BytesRange, - ) -> Result> { + ) -> Result> { let mut req = if self.key.is_some() { self.supabase_get_object_auth_request(path, range)? } else { @@ -239,7 +239,7 @@ impl SupabaseCore { self.send(req).await } - pub async fn supabase_head_object(&self, path: &str) -> Result> { + pub async fn supabase_head_object(&self, path: &str) -> Result> { let mut req = if self.key.is_some() { self.supabase_head_object_auth_request(path)? } else { @@ -249,7 +249,7 @@ impl SupabaseCore { self.send(req).await } - pub async fn supabase_get_object_info(&self, path: &str) -> Result> { + pub async fn supabase_get_object_info(&self, path: &str) -> Result> { let mut req = if self.key.is_some() { self.supabase_get_object_info_auth_request(path)? } else { @@ -259,7 +259,7 @@ impl SupabaseCore { self.send(req).await } - pub async fn supabase_delete_object(&self, path: &str) -> Result> { + pub async fn supabase_delete_object(&self, path: &str) -> Result> { let mut req = self.supabase_delete_object_request(path)?; self.sign(&mut req)?; self.send(req).await diff --git a/core/src/services/supabase/error.rs b/core/src/services/supabase/error.rs index 4e4602be1ebb..d2d3024d891b 100644 --- a/core/src/services/supabase/error.rs +++ b/core/src/services/supabase/error.rs @@ -22,9 +22,7 @@ use serde::Deserialize; use serde_json::from_slice; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; #[derive(Default, Debug, Deserialize)] #[serde(default, rename_all = "camelCase")] @@ -36,7 +34,7 @@ struct SupabaseError { } /// Parse the supabase error type to the OpenDAL error type -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/supabase/reader.rs b/core/src/services/supabase/reader.rs index 7554b57bd90c..544706502aa9 100644 --- a/core/src/services/supabase/reader.rs +++ b/core/src/services/supabase/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::SupabaseCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct SupabaseReader { core: Arc, @@ -41,7 +42,7 @@ impl SupabaseReader { } impl oio::Read for SupabaseReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.supabase_get_object(&self.path, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for SupabaseReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/swift/core.rs b/core/src/services/swift/core.rs index c1cd294e97c9..b1b6d33fe0bd 100644 --- a/core/src/services/swift/core.rs +++ b/core/src/services/swift/core.rs @@ -44,7 +44,7 @@ impl Debug for SwiftCore { } impl SwiftCore { - pub async fn swift_delete(&self, path: &str) -> Result> { + pub async fn swift_delete(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -71,7 +71,7 @@ impl SwiftCore { delimiter: &str, limit: Option, marker: &str, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); // The delimiter is used to disable recursive listing. @@ -107,7 +107,7 @@ impl SwiftCore { path: &str, length: u64, body: AsyncBody, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -132,7 +132,7 @@ impl SwiftCore { path: &str, range: BytesRange, _arg: &OpRead, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path) .trim_end_matches('/') .to_string(); @@ -159,7 +159,7 @@ impl SwiftCore { self.client.send(req).await } - pub async fn swift_copy(&self, src_p: &str, dst_p: &str) -> Result> { + pub async fn swift_copy(&self, src_p: &str, dst_p: &str) -> Result> { // NOTE: current implementation is limited to same container and root let src_p = format!( @@ -196,7 +196,7 @@ impl SwiftCore { self.client.send(req).await } - pub async fn swift_get_metadata(&self, path: &str) -> Result> { + pub async fn swift_get_metadata(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/swift/error.rs b/core/src/services/swift/error.rs index 6c956b20f442..e542298f68a9 100644 --- a/core/src/services/swift/error.rs +++ b/core/src/services/swift/error.rs @@ -23,9 +23,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; #[allow(dead_code)] #[derive(Debug, Deserialize)] @@ -34,7 +32,7 @@ struct ErrorResponse { p: String, } -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/swift/reader.rs b/core/src/services/swift/reader.rs index 885655761e73..7fe365b896f7 100644 --- a/core/src/services/swift/reader.rs +++ b/core/src/services/swift/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::SwiftCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct SwiftReader { core: Arc, @@ -41,7 +42,7 @@ impl SwiftReader { } impl oio::Read for SwiftReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.swift_read(&self.path, range, &self.op).await?; @@ -50,7 +51,7 @@ impl oio::Read for SwiftReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/upyun/core.rs b/core/src/services/upyun/core.rs index 1fcaf429db96..5c126ebfe29c 100644 --- a/core/src/services/upyun/core.rs +++ b/core/src/services/upyun/core.rs @@ -82,7 +82,7 @@ impl Debug for UpyunCore { impl UpyunCore { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -104,11 +104,7 @@ impl UpyunCore { } impl UpyunCore { - pub async fn download_file( - &self, - path: &str, - range: BytesRange, - ) -> Result> { + pub async fn download_file(&self, path: &str, range: BytesRange) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -129,7 +125,7 @@ impl UpyunCore { self.send(req).await } - pub async fn info(&self, path: &str) -> Result> { + pub async fn info(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -190,7 +186,7 @@ impl UpyunCore { Ok(req) } - pub async fn delete(&self, path: &str) -> Result> { + pub async fn delete(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -210,7 +206,7 @@ impl UpyunCore { self.send(req).await } - pub async fn copy(&self, from: &str, to: &str) -> Result> { + pub async fn copy(&self, from: &str, to: &str) -> Result> { let from = format!("/{}/{}", self.bucket, build_abs_path(&self.root, from)); let to = build_abs_path(&self.root, to); @@ -238,7 +234,7 @@ impl UpyunCore { self.send(req).await } - pub async fn move_object(&self, from: &str, to: &str) -> Result> { + pub async fn move_object(&self, from: &str, to: &str) -> Result> { let from = format!("/{}/{}", self.bucket, build_abs_path(&self.root, from)); let to = build_abs_path(&self.root, to); @@ -266,7 +262,7 @@ impl UpyunCore { self.send(req).await } - pub async fn create_dir(&self, path: &str) -> Result> { + pub async fn create_dir(&self, path: &str) -> Result> { let path = build_abs_path(&self.root, path); let path = path[..path.len() - 1].to_string(); @@ -295,7 +291,7 @@ impl UpyunCore { &self, path: &str, args: &OpWrite, - ) -> Result> { + ) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( @@ -369,7 +365,7 @@ impl UpyunCore { &self, path: &str, upload_id: &str, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -398,7 +394,7 @@ impl UpyunCore { path: &str, iter: &str, limit: Option, - ) -> Result> { + ) -> Result> { let path = build_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/upyun/error.rs b/core/src/services/upyun/error.rs index d3eec02d7b9b..116bac56e7fb 100644 --- a/core/src/services/upyun/error.rs +++ b/core/src/services/upyun/error.rs @@ -21,9 +21,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// UpyunError is the error returned by upyun service. #[derive(Default, Debug, Deserialize)] @@ -35,7 +33,7 @@ struct UpyunError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -88,7 +86,7 @@ mod test { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/upyun/reader.rs b/core/src/services/upyun/reader.rs index e2c129cf4f75..452bf5ff417e 100644 --- a/core/src/services/upyun/reader.rs +++ b/core/src/services/upyun/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::UpyunCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct UpyunReader { core: Arc, @@ -41,7 +42,7 @@ impl UpyunReader { } impl oio::Read for UpyunReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.download_file(&self.path, range).await?; @@ -50,7 +51,7 @@ impl oio::Read for UpyunReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/vercel_artifacts/backend.rs b/core/src/services/vercel_artifacts/backend.rs index b2e633df283d..eed541b031c3 100644 --- a/core/src/services/vercel_artifacts/backend.rs +++ b/core/src/services/vercel_artifacts/backend.rs @@ -109,7 +109,7 @@ impl VercelArtifactsBackend { hash: &str, range: BytesRange, _: &OpRead, - ) -> Result> { + ) -> Result> { let url: String = format!( "https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash) @@ -136,7 +136,7 @@ impl VercelArtifactsBackend { hash: &str, size: u64, body: AsyncBody, - ) -> Result> { + ) -> Result> { let url = format!( "https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash) @@ -154,7 +154,7 @@ impl VercelArtifactsBackend { self.client.send(req).await } - pub async fn vercel_artifacts_stat(&self, hash: &str) -> Result> { + pub async fn vercel_artifacts_stat(&self, hash: &str) -> Result> { let url = format!( "https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash) diff --git a/core/src/services/vercel_artifacts/error.rs b/core/src/services/vercel_artifacts/error.rs index 30a90f7a4f92..89724c826be2 100644 --- a/core/src/services/vercel_artifacts/error.rs +++ b/core/src/services/vercel_artifacts/error.rs @@ -20,12 +20,10 @@ use http::Response; use http::StatusCode; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/vercel_artifacts/reader.rs b/core/src/services/vercel_artifacts/reader.rs index 1e80edb23244..d60d1b4ec935 100644 --- a/core/src/services/vercel_artifacts/reader.rs +++ b/core/src/services/vercel_artifacts/reader.rs @@ -20,6 +20,7 @@ use http::StatusCode; use super::error::parse_error; use crate::raw::*; use crate::services::vercel_artifacts::backend::VercelArtifactsBackend; +use crate::*; pub struct VercelArtifactsReader { core: VercelArtifactsBackend, @@ -39,7 +40,7 @@ impl VercelArtifactsReader { } impl oio::Read for VercelArtifactsReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self @@ -51,7 +52,7 @@ impl oio::Read for VercelArtifactsReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/vercel_blob/core.rs b/core/src/services/vercel_blob/core.rs index 7ab84b11b6c0..836a15755cba 100644 --- a/core/src/services/vercel_blob/core.rs +++ b/core/src/services/vercel_blob/core.rs @@ -74,7 +74,7 @@ impl Debug for VercelBlobCore { impl VercelBlobCore { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -89,7 +89,7 @@ impl VercelBlobCore { path: &str, range: BytesRange, _: &OpRead, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); // Vercel blob use an unguessable random id url to download the file // So we use list to get the url of the file and then use it to download the file @@ -184,7 +184,7 @@ impl VercelBlobCore { } } - pub async fn head(&self, path: &str) -> Result> { + pub async fn head(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let resp = self.list(&p, Some(1)).await?; @@ -210,7 +210,7 @@ impl VercelBlobCore { self.send(req).await } - pub async fn copy(&self, from: &str, to: &str) -> Result> { + pub async fn copy(&self, from: &str, to: &str) -> Result> { let from = build_abs_path(&self.root, from); let resp = self.list(&from, Some(1)).await?; @@ -282,7 +282,7 @@ impl VercelBlobCore { &self, path: &str, args: &OpWrite, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -316,7 +316,7 @@ impl VercelBlobCore { part_number: usize, size: u64, body: AsyncBody, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( @@ -345,7 +345,7 @@ impl VercelBlobCore { path: &str, upload_id: &str, parts: Vec, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let url = format!( diff --git a/core/src/services/vercel_blob/error.rs b/core/src/services/vercel_blob/error.rs index 842b919c1629..2e66a1a72609 100644 --- a/core/src/services/vercel_blob/error.rs +++ b/core/src/services/vercel_blob/error.rs @@ -21,9 +21,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// VercelBlobError is the error returned by VercelBlob service. #[derive(Default, Debug, Deserialize)] @@ -40,7 +38,7 @@ struct VercelBlobErrorDetail { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -86,7 +84,7 @@ mod test { )]; for res in err_res { - let body = oio::Buffer::from(res.0.as_bytes().to_vec()); + let body = Buffer::from(res.0.as_bytes().to_vec()); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/vercel_blob/reader.rs b/core/src/services/vercel_blob/reader.rs index b43f4ec66f59..3cd99fc7b6d0 100644 --- a/core/src/services/vercel_blob/reader.rs +++ b/core/src/services/vercel_blob/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::VercelBlobCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct VercelBlobReader { core: Arc, @@ -41,7 +42,7 @@ impl VercelBlobReader { } impl oio::Read for VercelBlobReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.download(&self.path, range, &self.op).await?; @@ -50,7 +51,7 @@ impl oio::Read for VercelBlobReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/webdav/core.rs b/core/src/services/webdav/core.rs index 301f57202564..d7ad9a196a47 100644 --- a/core/src/services/webdav/core.rs +++ b/core/src/services/webdav/core.rs @@ -135,7 +135,7 @@ impl WebdavCore { path: &str, range: BytesRange, _: &OpRead, - ) -> Result> { + ) -> Result> { let path = build_rooted_abs_path(&self.root, path); let url: String = format!("{}{}", self.endpoint, percent_encode_path(&path)); @@ -162,7 +162,7 @@ impl WebdavCore { size: Option, args: &OpWrite, body: AsyncBody, - ) -> Result> { + ) -> Result> { let path = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&path)); @@ -189,7 +189,7 @@ impl WebdavCore { self.client.send(req).await } - pub async fn webdav_delete(&self, path: &str) -> Result> { + pub async fn webdav_delete(&self, path: &str) -> Result> { let path = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&path)); @@ -206,7 +206,7 @@ impl WebdavCore { self.client.send(req).await } - pub async fn webdav_copy(&self, from: &str, to: &str) -> Result> { + pub async fn webdav_copy(&self, from: &str, to: &str) -> Result> { // Check if source file exists. let _ = self.webdav_stat(from).await?; // Make sure target's dir is exist. @@ -234,7 +234,7 @@ impl WebdavCore { self.client.send(req).await } - pub async fn webdav_move(&self, from: &str, to: &str) -> Result> { + pub async fn webdav_move(&self, from: &str, to: &str) -> Result> { // Check if source file exists. let _ = self.webdav_stat(from).await?; // Make sure target's dir is exist. @@ -262,7 +262,7 @@ impl WebdavCore { self.client.send(req).await } - pub async fn webdav_list(&self, path: &str, args: &OpList) -> Result> { + pub async fn webdav_list(&self, path: &str, args: &OpList) -> Result> { let path = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&path)); diff --git a/core/src/services/webdav/error.rs b/core/src/services/webdav/error.rs index 930c136a13c6..8282fe4b5dce 100644 --- a/core/src/services/webdav/error.rs +++ b/core/src/services/webdav/error.rs @@ -20,12 +20,10 @@ use http::Response; use http::StatusCode; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); diff --git a/core/src/services/webdav/reader.rs b/core/src/services/webdav/reader.rs index b7d6426b7d7d..83c09398e47c 100644 --- a/core/src/services/webdav/reader.rs +++ b/core/src/services/webdav/reader.rs @@ -22,6 +22,7 @@ use http::StatusCode; use super::core::WebdavCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct WebdavReader { core: Arc, @@ -41,7 +42,7 @@ impl WebdavReader { } impl oio::Read for WebdavReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.webdav_get(&self.path, range, &self.op).await?; @@ -50,7 +51,7 @@ impl oio::Read for WebdavReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/webhdfs/backend.rs b/core/src/services/webhdfs/backend.rs index a9d3dd7c0d50..c3ccf29a02ca 100644 --- a/core/src/services/webhdfs/backend.rs +++ b/core/src/services/webhdfs/backend.rs @@ -318,11 +318,7 @@ impl WebhdfsBackend { } } - pub async fn webhdfs_rename_object( - &self, - from: &str, - to: &str, - ) -> Result> { + pub async fn webhdfs_rename_object(&self, from: &str, to: &str) -> Result> { let from = build_abs_path(&self.root, from); let to = build_rooted_abs_path(&self.root, to); @@ -422,7 +418,7 @@ impl WebhdfsBackend { Ok(req) } - pub async fn webhdfs_list_status_request(&self, path: &str) -> Result> { + pub async fn webhdfs_list_status_request(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let mut url = format!( "{}/webhdfs/v1/{}?op=LISTSTATUS", @@ -443,7 +439,7 @@ impl WebhdfsBackend { &self, path: &str, start_after: &str, - ) -> Result> { + ) -> Result> { let p = build_abs_path(&self.root, path); let mut url = format!( @@ -468,15 +464,12 @@ impl WebhdfsBackend { &self, path: &str, range: BytesRange, - ) -> Result> { + ) -> Result> { let req = self.webhdfs_open_request(path, &range).await?; self.client.send(req).await } - pub(super) async fn webhdfs_get_file_status( - &self, - path: &str, - ) -> Result> { + pub(super) async fn webhdfs_get_file_status(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let mut url = format!( "{}/webhdfs/v1/{}?op=GETFILESTATUS", @@ -495,7 +488,7 @@ impl WebhdfsBackend { self.client.send(req).await } - pub async fn webhdfs_delete(&self, path: &str) -> Result> { + pub async fn webhdfs_delete(&self, path: &str) -> Result> { let p = build_abs_path(&self.root, path); let mut url = format!( "{}/webhdfs/v1/{}?op=DELETE&recursive=false", diff --git a/core/src/services/webhdfs/error.rs b/core/src/services/webhdfs/error.rs index 971997a7be8b..8a9efffb98ba 100644 --- a/core/src/services/webhdfs/error.rs +++ b/core/src/services/webhdfs/error.rs @@ -40,7 +40,7 @@ struct WebHdfsError { java_class_name: String, } -pub(super) async fn parse_error(resp: Response) -> Result { +pub(super) async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); let s = String::from_utf8_lossy(&bs); @@ -99,7 +99,7 @@ mod tests { } "#, ); - let body = oio::Buffer::from(ill_args.clone()); + let body = Buffer::from(ill_args.clone()); let resp = Response::builder() .status(StatusCode::BAD_REQUEST) .body(body) diff --git a/core/src/services/webhdfs/reader.rs b/core/src/services/webhdfs/reader.rs index 76786398f878..30c8dcbfb5b4 100644 --- a/core/src/services/webhdfs/reader.rs +++ b/core/src/services/webhdfs/reader.rs @@ -22,6 +22,7 @@ use super::error::parse_error; use super::error::parse_error_msg; use crate::raw::*; use crate::services::webhdfs::backend::WebhdfsBackend; +use crate::*; pub struct WebhdfsReader { core: WebhdfsBackend, @@ -41,7 +42,7 @@ impl WebhdfsReader { } impl oio::Read for WebhdfsReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); let resp = self.core.webhdfs_read_file(&self.path, range).await?; @@ -56,12 +57,12 @@ impl oio::Read for WebhdfsReader { let bs = body.copy_to_bytes(body.remaining()); let s = String::from_utf8_lossy(&bs); if s.contains("out of the range") { - Ok(oio::Buffer::new()) + Ok(Buffer::new()) } else { Err(parse_error_msg(parts, &s)?) } } - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/services/yandex_disk/core.rs b/core/src/services/yandex_disk/core.rs index 7c76f4d47f2a..f46c38ac2e9a 100644 --- a/core/src/services/yandex_disk/core.rs +++ b/core/src/services/yandex_disk/core.rs @@ -50,7 +50,7 @@ impl Debug for YandexDiskCore { impl YandexDiskCore { #[inline] - pub async fn send(&self, req: Request) -> Result> { + pub async fn send(&self, req: Request) -> Result> { self.client.send(req).await } @@ -152,7 +152,7 @@ impl YandexDiskCore { Ok(()) } - pub async fn create_dir(&self, path: &str) -> Result> { + pub async fn create_dir(&self, path: &str) -> Result> { let url = format!( "https://cloud-api.yandex.net/v1/disk/resources?path=/{}", percent_encode_path(path), @@ -170,7 +170,7 @@ impl YandexDiskCore { self.send(req).await } - pub async fn copy(&self, from: &str, to: &str) -> Result> { + pub async fn copy(&self, from: &str, to: &str) -> Result> { let from = build_rooted_abs_path(&self.root, from); let to = build_rooted_abs_path(&self.root, to); @@ -192,7 +192,7 @@ impl YandexDiskCore { self.send(req).await } - pub async fn move_object(&self, from: &str, to: &str) -> Result> { + pub async fn move_object(&self, from: &str, to: &str) -> Result> { let from = build_rooted_abs_path(&self.root, from); let to = build_rooted_abs_path(&self.root, to); @@ -214,7 +214,7 @@ impl YandexDiskCore { self.send(req).await } - pub async fn delete(&self, path: &str) -> Result> { + pub async fn delete(&self, path: &str) -> Result> { let path = build_rooted_abs_path(&self.root, path); let url = format!( @@ -239,7 +239,7 @@ impl YandexDiskCore { path: &str, limit: Option, offset: Option, - ) -> Result> { + ) -> Result> { let path = build_rooted_abs_path(&self.root, path); let mut url = format!( diff --git a/core/src/services/yandex_disk/error.rs b/core/src/services/yandex_disk/error.rs index 38e6e3c72f8b..e6ece2bee218 100644 --- a/core/src/services/yandex_disk/error.rs +++ b/core/src/services/yandex_disk/error.rs @@ -21,9 +21,7 @@ use quick_xml::de; use serde::Deserialize; use crate::raw::*; -use crate::Error; -use crate::ErrorKind; -use crate::Result; +use crate::*; /// YandexDiskError is the error returned by YandexDisk service. #[derive(Default, Debug, Deserialize)] @@ -35,7 +33,7 @@ struct YandexDiskError { } /// Parse error response into Error. -pub async fn parse_error(resp: Response) -> Result { +pub async fn parse_error(resp: Response) -> Result { let (parts, mut body) = resp.into_parts(); let bs = body.copy_to_bytes(body.remaining()); @@ -96,7 +94,7 @@ mod test { for res in err_res { let bs = bytes::Bytes::from(res.0); - let body = oio::Buffer::from(bs); + let body = Buffer::from(bs); let resp = Response::builder().status(res.2).body(body).unwrap(); let err = parse_error(resp).await; diff --git a/core/src/services/yandex_disk/reader.rs b/core/src/services/yandex_disk/reader.rs index ec9f3ffd437e..24cde9e96e43 100644 --- a/core/src/services/yandex_disk/reader.rs +++ b/core/src/services/yandex_disk/reader.rs @@ -24,6 +24,7 @@ use http::StatusCode; use super::core::YandexDiskCore; use super::error::parse_error; use crate::raw::*; +use crate::*; pub struct YandexDiskReader { core: Arc, @@ -43,7 +44,7 @@ impl YandexDiskReader { } impl oio::Read for YandexDiskReader { - async fn read_at(&self, offset: u64, limit: usize) -> crate::Result { + async fn read_at(&self, offset: u64, limit: usize) -> Result { let range = BytesRange::new(offset, Some(limit as u64)); // TODO: move this out of reader. @@ -59,7 +60,7 @@ impl oio::Read for YandexDiskReader { match status { StatusCode::OK | StatusCode::PARTIAL_CONTENT => Ok(resp.into_body()), - StatusCode::RANGE_NOT_SATISFIABLE => Ok(oio::Buffer::new()), + StatusCode::RANGE_NOT_SATISFIABLE => Ok(Buffer::new()), _ => Err(parse_error(resp).await?), } } diff --git a/core/src/types/blocking_reader.rs b/core/src/types/blocking_reader.rs index 5e86e6de68d1..37d2d6c914b4 100644 --- a/core/src/types/blocking_reader.rs +++ b/core/src/types/blocking_reader.rs @@ -139,8 +139,8 @@ pub mod into_std_read { use bytes::Buf; - use crate::raw::format_std_io_error; - use crate::raw::oio; + use crate::raw::*; + use crate::*; /// StdReader is the adapter of [`Read`], [`Seek`] and [`BufRead`] for [`BlockingReader`][crate::BlockingReader]. /// @@ -154,7 +154,7 @@ pub mod into_std_read { cap: usize, cur: u64, - buf: oio::Buffer, + buf: Buffer, } impl StdIoReader { @@ -169,7 +169,7 @@ pub mod into_std_read { cap: 4 * 1024 * 1024, cur: 0, - buf: oio::Buffer::new(), + buf: Buffer::new(), } } @@ -239,7 +239,7 @@ pub mod into_std_read { let cnt = new_pos - self.cur; self.buf.advance(cnt as _); } else { - self.buf = oio::Buffer::new() + self.buf = Buffer::new() } self.cur = new_pos; diff --git a/core/src/raw/oio/buf/buffer.rs b/core/src/types/buffer.rs similarity index 100% rename from core/src/raw/oio/buf/buffer.rs rename to core/src/types/buffer.rs diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs index da246e64cdb8..7e5523bb90ee 100644 --- a/core/src/types/mod.rs +++ b/core/src/types/mod.rs @@ -18,6 +18,9 @@ mod mode; pub use mode::EntryMode; +mod buffer; +pub use buffer::Buffer; + mod entry; pub use entry::Entry; @@ -64,5 +67,4 @@ mod scheme; pub use scheme::Scheme; mod capability; - pub use capability::Capability; diff --git a/core/src/types/reader.rs b/core/src/types/reader.rs index e402f915ea33..7a6f17d9193e 100644 --- a/core/src/types/reader.rs +++ b/core/src/types/reader.rs @@ -168,12 +168,12 @@ pub mod into_futures_async_read { cap: usize, cur: u64, - buf: oio::Buffer, + buf: Buffer, } enum State { Idle(Option), - Fill(BoxedStaticFuture<(oio::Reader, Result)>), + Fill(BoxedStaticFuture<(oio::Reader, Result)>), } /// # Safety @@ -193,7 +193,7 @@ pub mod into_futures_async_read { cap: 4 * 1024 * 1024, cur: 0, - buf: oio::Buffer::new(), + buf: Buffer::new(), } } @@ -282,7 +282,7 @@ pub mod into_futures_async_read { let cnt = new_pos - self.cur; self.buf.advance(cnt as _); } else { - self.buf = oio::Buffer::new() + self.buf = Buffer::new() } self.cur = new_pos; @@ -322,7 +322,7 @@ pub mod into_futures_stream { enum State { Idle(Option), - Next(BoxedStaticFuture<(oio::Reader, Result)>), + Next(BoxedStaticFuture<(oio::Reader, Result)>), } /// # Safety diff --git a/core/src/types/writer.rs b/core/src/types/writer.rs index d2a41d721e7d..557abc898c0f 100644 --- a/core/src/types/writer.rs +++ b/core/src/types/writer.rs @@ -239,7 +239,7 @@ pub mod into_futures_async_write { let bs = this.buf.get().expect("frozen buffer must be valid"); let mut w = w.take().expect("writer must be valid"); let fut = async move { - let res = w.write(oio::Buffer::from(bs)).await; + let res = w.write(Buffer::from(bs)).await; (w, res) }; this.state = State::Writing(Box::pin(fut)); @@ -277,7 +277,7 @@ pub mod into_futures_async_write { let mut w = w.take().expect("writer must be valid"); let fut = async move { - let res = w.write(oio::Buffer::from(bs)).await; + let res = w.write(Buffer::from(bs)).await; (w, res) }; this.state = State::Writing(Box::pin(fut));