From 47a20d8df6fb727b6f34122e80430703eb50755d Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 5 Jun 2024 22:26:18 +0800 Subject: [PATCH 1/3] Fix all broken links Signed-off-by: Xuanwo --- CHANGELOG.md | 10 ++-- core/src/docs/internals/accessor.rs | 2 +- core/src/docs/mod.rs | 3 ++ .../docs/rfcs/3017_remove_write_copy_from.md | 2 +- core/src/docs/upgrade.md | 4 +- core/src/layers/prometheus_client.rs | 2 +- core/src/raw/oio/list/page_list.rs | 4 +- core/src/raw/oio/read/api.rs | 2 +- core/src/raw/oio/write/api.rs | 6 --- core/src/raw/oio/write/append_write.rs | 4 +- core/src/raw/oio/write/block_write.rs | 7 ++- core/src/raw/oio/write/multipart_write.rs | 4 +- core/src/raw/oio/write/one_shot_write.rs | 4 +- core/src/raw/oio/write/range_write.rs | 4 +- core/src/services/icloud/docs.md | 2 +- core/src/services/koofr/backend.rs | 2 +- core/src/services/mysql/backend.rs | 2 +- core/src/services/pcloud/backend.rs | 2 +- core/src/services/s3/compatible_services.md | 4 +- core/src/services/sqlite/backend.rs | 4 +- core/src/services/tikv/docs.md | 2 +- .../types/blocking_read/blocking_reader.rs | 2 +- core/src/types/execute/executor.rs | 2 +- core/src/types/execute/executors/mod.rs | 4 +- core/src/types/operator/blocking_operator.rs | 11 +++-- core/src/types/operator/operator.rs | 17 +++---- core/src/types/read/reader.rs | 48 ++++++++++++++++++- core/src/types/scheme.rs | 14 +++--- core/src/types/write/buffer_sink.rs | 4 +- core/src/types/write/futures_bytes_sink.rs | 4 +- core/src/types/write/writer.rs | 48 ++++++++++++++++--- 31 files changed, 153 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8809238d3..3b96e4f063d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -342,14 +342,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ### Changed * refactor: Merge compose_{read,write} into enum_utils by @Xuanwo in https://github.com/apache/opendal/pull/3871 -* refactor(services/ftp): Impl parse_error instead of From by @bokket in https://github.com/apache/opendal/pull/3891 +* refactor(services/ftp): Impl parse_error instead of `From` by @bokket in https://github.com/apache/opendal/pull/3891 * docs: very minor English wording fix in error message by @gabrielgrant in https://github.com/apache/opendal/pull/3900 -* refactor(services/rocksdb): Impl parse_error instead of From by @suyanhanx in https://github.com/apache/opendal/pull/3903 +* refactor(services/rocksdb): Impl parse_error instead of `From` by @suyanhanx in https://github.com/apache/opendal/pull/3903 * refactor: Re-organize the layout of tests by @Xuanwo in https://github.com/apache/opendal/pull/3904 -* refactor(services/etcd): Impl parse_error instead of From by @suyanhanx in https://github.com/apache/opendal/pull/3910 -* refactor(services/sftp): Impl parse_error instead of From by @G-XD in https://github.com/apache/opendal/pull/3914 +* refactor(services/etcd): Impl parse_error instead of `From` by @suyanhanx in https://github.com/apache/opendal/pull/3910 +* refactor(services/sftp): Impl parse_error instead of `From` by @G-XD in https://github.com/apache/opendal/pull/3914 * refactor!: Bump MSRV to 1.75 by @Xuanwo in https://github.com/apache/opendal/pull/3851 -* refactor(services/redis): Impl parse_error instead of From by @suyanhanx in https://github.com/apache/opendal/pull/3938 +* refactor(services/redis): Impl parse_error instead of `From` by @suyanhanx in https://github.com/apache/opendal/pull/3938 * refactor!: Revert the bump of MSRV to 1.75 by @Xuanwo in https://github.com/apache/opendal/pull/3952 * refactor(services/onedrive): Add OnedriveConfig to implement ConfigDeserializer by @Borber in https://github.com/apache/opendal/pull/3954 * refactor(service/dropbox): Add DropboxConfig by @howiieyu in https://github.com/apache/opendal/pull/3961 diff --git a/core/src/docs/internals/accessor.rs b/core/src/docs/internals/accessor.rs index c10800883e8..ca0480d45b4 100644 --- a/core/src/docs/internals/accessor.rs +++ b/core/src/docs/internals/accessor.rs @@ -321,6 +321,6 @@ //! [`Access`]: crate::raw::Access //! [`Operation`]: crate::raw::Operation //! [`Capability`]: crate::Capability -//! [`AccessorInfo`]: crate::raw::AccessInfo +//! [`AccessorInfo`]: crate::raw::AccessorInfo //! [`Scheme`]: crate::Scheme //! [`Builder`]: crate::Builder diff --git a/core/src/docs/mod.rs b/core/src/docs/mod.rs index 4da07dd00b0..5d39c17a3af 100644 --- a/core/src/docs/mod.rs +++ b/core/src/docs/mod.rs @@ -19,6 +19,8 @@ //! //! It's highly recommended that you start by reading [`concepts`] first. +#![allow(rustdoc::bare_urls)] + pub mod comparisons; pub mod concepts; @@ -27,6 +29,7 @@ pub mod internals; /// Changes log for all OpenDAL released versions. #[doc = include_str!("../../CHANGELOG.md")] +#[cfg(not(doctest))] pub mod changelog {} #[cfg(not(doctest))] diff --git a/core/src/docs/rfcs/3017_remove_write_copy_from.md b/core/src/docs/rfcs/3017_remove_write_copy_from.md index ad14825718b..b5344071b03 100644 --- a/core/src/docs/rfcs/3017_remove_write_copy_from.md +++ b/core/src/docs/rfcs/3017_remove_write_copy_from.md @@ -12,7 +12,7 @@ Remove the `oio::Write::copy_from()` API pending a more thoughtful design. In [RFC-2083: Writer Sink API](./2083_writer_sink_api.md), we launched an API, initially named `sink` and changed to `copy_from`, that enables data writing from a `Reader` to a `Writer` object. The current API signature is: - +s ```rust pub trait Write: Unpin + Send + Sync { /// Copies data from the given reader to the writer. diff --git a/core/src/docs/upgrade.md b/core/src/docs/upgrade.md index 7e9d2e5d574..b4f35b81f3d 100644 --- a/core/src/docs/upgrade.md +++ b/core/src/docs/upgrade.md @@ -205,7 +205,7 @@ There is no public API and raw API changes. ### RFC-2578 Merge Append Into Write -[RFC-2578](crate::docs::rfcs::rfc_2578_merge_append_into_write) merges `append` into `write` and removes `append` API. +[RFC-2578](crate::docs::rfcs::rfc_2758_merge_append_into_write) merges `append` into `write` and removes `append` API. - For writing a file at once, please use `op.write()` for convenience. - For appending a file, please use `op.write_with().append(true)` instead of `op.append()`. @@ -291,7 +291,7 @@ OpenDAL v0.40 removed the origin `range_read` and `range_reader` interfaces, ple ### RFC-3017 Remove Write Copy From -[RFC-3017](opendal::docs::rfcs::rfc_3017_remove_write_copy_from) removes `copy_from` API from the `oio::Write` trait. Users who implements services and layers by hand should remove this API. +[RFC-3017](crate::docs::rfcs::rfc_3017_remove_write_copy_from) removes `copy_from` API from the `oio::Write` trait. Users who implements services and layers by hand should remove this API. # Upgrade to v0.39 diff --git a/core/src/layers/prometheus_client.rs b/core/src/layers/prometheus_client.rs index a6a569005a6..25d27456e35 100644 --- a/core/src/layers/prometheus_client.rs +++ b/core/src/layers/prometheus_client.rs @@ -86,7 +86,7 @@ pub struct PrometheusClientLayer { impl PrometheusClientLayer { /// Create PrometheusClientLayer while registering itself to this registry. Please keep in caution /// that do NOT call this method multiple times with a same registry. If you want initialize multiple - /// [`PrometheusClientLayer`] with a single registry, you should use [`clone`] instead. + /// [`PrometheusClientLayer`] with a single registry, you should use [`Arc::clone`] instead. pub fn new(registry: &mut Registry) -> Self { let metrics = PrometheusClientMetrics::register(registry); Self { metrics } diff --git a/core/src/raw/oio/list/page_list.rs b/core/src/raw/oio/list/page_list.rs index 9ba141be800..4cce1209011 100644 --- a/core/src/raw/oio/list/page_list.rs +++ b/core/src/raw/oio/list/page_list.rs @@ -21,7 +21,7 @@ use std::future::Future; use crate::raw::*; use crate::*; -/// PageList is used to implement [`List`] based on API supporting pagination. By implementing +/// PageList is used to implement [`oio::List`] based on API supporting pagination. By implementing /// PageList, services don't need to care about the details of page list. /// /// # Architecture @@ -62,7 +62,7 @@ pub struct PageContext { pub entries: VecDeque, } -/// PageLister implements [`List`] based on [`PageList`]. +/// PageLister implements [`oio::List`] based on [`PageList`]. pub struct PageLister { inner: L, ctx: PageContext, diff --git a/core/src/raw/oio/read/api.rs b/core/src/raw/oio/read/api.rs index 88bfcdedc40..3a003e6a320 100644 --- a/core/src/raw/oio/read/api.rs +++ b/core/src/raw/oio/read/api.rs @@ -121,7 +121,7 @@ impl Read for Buffer { /// ReadDyn is the dyn version of [`Read`] make it possible to use as /// `Box`. pub trait ReadDyn: Unpin + Send + Sync { - /// The dyn version of [`Read::read_at`]. + /// The dyn version of [`Read::read`]. /// /// This function returns a boxed future to make it object safe. fn read_dyn(&mut self) -> BoxedFuture>; diff --git a/core/src/raw/oio/write/api.rs b/core/src/raw/oio/write/api.rs index de74c76ef00..e6c7c05918e 100644 --- a/core/src/raw/oio/write/api.rs +++ b/core/src/raw/oio/write/api.rs @@ -170,12 +170,6 @@ pub trait BlockingWrite: Send + Sync + 'static { /// /// It's possible that `n < bs.len()`, caller should pass the remaining bytes /// repeatedly until all bytes has been written. - /// - /// # Safety - /// - /// - 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: Buffer) -> Result; /// Close the writer and make sure all data has been flushed. diff --git a/core/src/raw/oio/write/append_write.rs b/core/src/raw/oio/write/append_write.rs index a7f0fbae6dd..2f48b683079 100644 --- a/core/src/raw/oio/write/append_write.rs +++ b/core/src/raw/oio/write/append_write.rs @@ -20,7 +20,7 @@ use std::future::Future; use crate::raw::*; use crate::*; -/// AppendWrite is used to implement [`Write`] based on append +/// AppendWrite is used to implement [`oio::Write`] based on append /// object. By implementing AppendWrite, services don't need to /// care about the details of buffering and uploading parts. /// @@ -51,7 +51,7 @@ pub trait AppendWrite: Send + Sync + Unpin + 'static { ) -> impl Future> + MaybeSend; } -/// AppendWriter will implements [`Write`] based on append object. +/// AppendWriter will implements [`oio::Write`] based on append object. /// /// ## TODO /// diff --git a/core/src/raw/oio/write/block_write.rs b/core/src/raw/oio/write/block_write.rs index 8d2fd2508cf..d1c13700e33 100644 --- a/core/src/raw/oio/write/block_write.rs +++ b/core/src/raw/oio/write/block_write.rs @@ -28,7 +28,7 @@ use uuid::Uuid; use crate::raw::*; use crate::*; -/// BlockWrite is used to implement [`Write`] based on block +/// BlockWrite is used to implement [`oio::Write`] based on block /// uploads. By implementing BlockWrite, services don't need to /// care about the details of uploading blocks. /// @@ -67,8 +67,7 @@ pub trait BlockWrite: Send + Sync + Unpin + 'static { /// - All the data has been written to the buffer and we can perform the upload at once. fn write_once(&self, size: u64, body: Buffer) -> impl Future> + MaybeSend; - /// write_block will write a block of the data and returns the result - /// [`Block`]. + /// write_block will write a block of the data. /// /// BlockWriter will call this API and stores the result in /// order. @@ -128,7 +127,7 @@ impl WriteBlockFuture { } } -/// BlockWriter will implements [`Write`] based on block +/// BlockWriter will implements [`oio::Write`] based on block /// uploads. pub struct BlockWriter { w: Arc, diff --git a/core/src/raw/oio/write/multipart_write.rs b/core/src/raw/oio/write/multipart_write.rs index 59e8d2725ff..0f0963de014 100644 --- a/core/src/raw/oio/write/multipart_write.rs +++ b/core/src/raw/oio/write/multipart_write.rs @@ -23,7 +23,7 @@ use futures::{select, Future}; use crate::raw::*; use crate::*; -/// MultipartWrite is used to implement [`Write`] based on multipart +/// MultipartWrite is used to implement [`oio::Write`] based on multipart /// uploads. By implementing MultipartWrite, services don't need to /// care about the details of uploading parts. /// @@ -123,7 +123,7 @@ struct WriteInput { bytes: Buffer, } -/// MultipartWriter will implements [`Write`] based on multipart +/// MultipartWriter will implements [`oio::Write`] based on multipart /// uploads. pub struct MultipartWriter { w: Arc, diff --git a/core/src/raw/oio/write/one_shot_write.rs b/core/src/raw/oio/write/one_shot_write.rs index 09e9b4f8f0b..cd056c14614 100644 --- a/core/src/raw/oio/write/one_shot_write.rs +++ b/core/src/raw/oio/write/one_shot_write.rs @@ -20,7 +20,7 @@ use std::future::Future; use crate::raw::*; use crate::*; -/// OneShotWrite is used to implement [`Write`] based on one shot operation. +/// OneShotWrite is used to implement [`oio::Write`] based on one shot operation. /// By implementing OneShotWrite, services don't need to care about the details. /// /// For example, S3 `PUT Object` and fs `write_all`. @@ -33,7 +33,7 @@ pub trait OneShotWrite: Send + Sync + Unpin + 'static { fn write_once(&self, bs: Buffer) -> impl Future> + MaybeSend; } -/// OneShotWrite is used to implement [`Write`] based on one shot. +/// OneShotWrite is used to implement [`oio::Write`] based on one shot. pub struct OneShotWriter { inner: W, buffer: Option, diff --git a/core/src/raw/oio/write/range_write.rs b/core/src/raw/oio/write/range_write.rs index 9e76f50db59..66c9d7a39d3 100644 --- a/core/src/raw/oio/write/range_write.rs +++ b/core/src/raw/oio/write/range_write.rs @@ -27,7 +27,7 @@ use futures::StreamExt; use crate::raw::*; use crate::*; -/// RangeWrite is used to implement [`Write`] based on range write. +/// RangeWrite is used to implement [`oio::Write`] based on range write. /// /// # Services /// @@ -130,7 +130,7 @@ impl WriteRangeFuture { } } -/// RangeWriter will implements [`Write`] based on range write. +/// RangeWriter will implements [`oio::Write`] based on range write. pub struct RangeWriter { location: Option>, next_offset: u64, diff --git a/core/src/services/icloud/docs.md b/core/src/services/icloud/docs.md index d3789f7ad21..46f7cbabd8f 100644 --- a/core/src/services/icloud/docs.md +++ b/core/src/services/icloud/docs.md @@ -26,7 +26,7 @@ This service can be used to: - `ds_web_auth_token`: set the ds_web_auth_token for icloud drive api Get web trust the session. - `is_china_mainland`: set the is_china_mainland for icloud drive api - China region must true to use "https://www.icloud.com.cn" + China region must true to use Otherwise Apple server will return 302. More information you can get [apple.com](https://support.apple.com/en-us/111754) diff --git a/core/src/services/koofr/backend.rs b/core/src/services/koofr/backend.rs index 90a6863ecce..71781b13661 100644 --- a/core/src/services/koofr/backend.rs +++ b/core/src/services/koofr/backend.rs @@ -118,7 +118,7 @@ impl KoofrBuilder { /// Koofr application password. /// - /// Go to https://app.koofr.net/app/admin/preferences/password. + /// Go to . /// Click "Generate Password" button to generate a new application password. /// /// # Notes diff --git a/core/src/services/mysql/backend.rs b/core/src/services/mysql/backend.rs index 0f55233ecf6..06c43d36594 100644 --- a/core/src/services/mysql/backend.rs +++ b/core/src/services/mysql/backend.rs @@ -77,7 +77,7 @@ impl MysqlBuilder { /// /// ## Url /// - /// This format resembles the url format of the mysql client. The format is: [scheme://][user[:[password]]@]host[:port][/schema][?attribute1=value1&attribute2=value2... + /// This format resembles the url format of the mysql client. The format is: `[scheme://][user[:[password]]@]host[:port][/schema][?attribute1=value1&attribute2=value2...` /// /// - `mysql://user@localhost` /// - `mysql://user:password@localhost` diff --git a/core/src/services/pcloud/backend.rs b/core/src/services/pcloud/backend.rs index d924453929f..b7bf90807e7 100644 --- a/core/src/services/pcloud/backend.rs +++ b/core/src/services/pcloud/backend.rs @@ -97,7 +97,7 @@ impl PcloudBuilder { } /// Pcloud endpoint. - /// https://api.pcloud.com for United States and https://eapi.pcloud.com for Europe + /// for United States and for Europe /// ref to [doc.pcloud.com](https://docs.pcloud.com/) /// /// It is required. e.g. `https://api.pcloud.com` diff --git a/core/src/services/s3/compatible_services.md b/core/src/services/s3/compatible_services.md index 8226e6665df..12a6e270ee6 100644 --- a/core/src/services/s3/compatible_services.md +++ b/core/src/services/s3/compatible_services.md @@ -117,10 +117,10 @@ To connect to r2, we need to set: [Google Cloud Storage XML API](https://cloud.google.com/storage/docs/xml-api/overview) provides s3 compatible API. - `endpoint`: The endpoint of Google Cloud Storage XML API, for example: `https://storage.googleapis.com` - `bucket`: The bucket name. -- To access GCS via S3 API, please enable `features = ["native-tls"]` in your `Cargo.toml` to avoid connection being reset when using `rustls`. Tracking in https://github.com/seanmonstar/reqwest/issues/1809 +- To access GCS via S3 API, please enable `features = ["native-tls"]` in your `Cargo.toml` to avoid connection being reset when using `rustls`. Tracking in ### Ceph Rados Gateway Ceph supports a RESTful API that is compatible with the basic data access model of the Amazon S3 API. -For more information, refer: https://docs.ceph.com/en/latest/radosgw/s3/ +For more information, refer: diff --git a/core/src/services/sqlite/backend.rs b/core/src/services/sqlite/backend.rs index c715ab23349..d91e210807a 100644 --- a/core/src/services/sqlite/backend.rs +++ b/core/src/services/sqlite/backend.rs @@ -39,7 +39,7 @@ pub struct SqliteConfig { /// /// ## Url /// - /// This format resembles the url format of the sqlite client. The format is: file://[path]?flag + /// This format resembles the url format of the sqlite client. The format is: `file://[path]?flag` /// /// - `file://data.db` /// @@ -98,7 +98,7 @@ impl SqliteBuilder { /// /// ## Url /// - /// This format resembles the url format of the sqlite client. The format is: file://[path]?flag + /// This format resembles the url format of the sqlite client. The format is: `file://[path]?flag` /// /// - `file://data.db` /// diff --git a/core/src/services/tikv/docs.md b/core/src/services/tikv/docs.md index e1fafcf7da7..642374892c9 100644 --- a/core/src/services/tikv/docs.md +++ b/core/src/services/tikv/docs.md @@ -21,7 +21,7 @@ This service can be used to: - `cert_path`: Set the cert path to the tikv connection - `key_path`: Set the key path to the tikv connection -You can refer to [`TiKVBuilder`]'s docs for more information +You can refer to [`TikvBuilder`]'s docs for more information ## Example diff --git a/core/src/types/blocking_read/blocking_reader.rs b/core/src/types/blocking_read/blocking_reader.rs index 857bb9a9d2e..9d79f90abaa 100644 --- a/core/src/types/blocking_read/blocking_reader.rs +++ b/core/src/types/blocking_read/blocking_reader.rs @@ -83,7 +83,7 @@ impl BlockingReader { /// Read give range from reader into [`Buffer`]. /// - /// This operation is zero-copy, which means it keeps the [`Bytes`] returned by underlying + /// This operation is zero-copy, which means it keeps the [`bytes::Bytes`] returned by underlying /// storage services without any extra copy or intensive memory allocations. /// /// # Notes diff --git a/core/src/types/execute/executor.rs b/core/src/types/execute/executor.rs index b5f8321d9f4..80f20427ad2 100644 --- a/core/src/types/execute/executor.rs +++ b/core/src/types/execute/executor.rs @@ -27,7 +27,7 @@ use std::sync::Arc; /// Executor is created by users and used by opendal. So it's by design that Executor only /// expose constructor methods. /// -/// Executor will run futures in background and return a [`Task`] as handle to the future. Users +/// Executor will run futures in background and return a `Task` as handle to the future. Users /// can call `task.await` to wait for the future to complete or drop the `Task` to cancel it. #[derive(Clone)] pub struct Executor { diff --git a/core/src/types/execute/executors/mod.rs b/core/src/types/execute/executors/mod.rs index d3e79f37233..4b79edf5299 100644 --- a/core/src/types/execute/executors/mod.rs +++ b/core/src/types/execute/executors/mod.rs @@ -15,11 +15,11 @@ // specific language governing permissions and limitations // under the License. -//! executors module provides implementations for the [`Execute`] trait for widely used runtimes. +//! executors module provides implementations for the [`Execute`](crate::Execute) trait for widely used runtimes. //! //! Every executor will be hide behind the feature like `executors-xxx`. Users can switch or enable //! the executors they want by enabling the corresponding feature. Also, users can provide their -//! own executor by implementing the [`Execute`] trait directly. +//! own executor by implementing the [`Execute`](crate::Execute) trait directly. #[cfg(feature = "executors-tokio")] mod tokio_executor; diff --git a/core/src/types/operator/blocking_operator.rs b/core/src/types/operator/blocking_operator.rs index 8d2344778b8..56832b0f260 100644 --- a/core/src/types/operator/blocking_operator.rs +++ b/core/src/types/operator/blocking_operator.rs @@ -143,9 +143,9 @@ impl BlockingOperator { /// /// # Notes /// - /// For fetch metadata of entries returned by [`Lister`], it's better to use [`list_with`] and - /// [`lister_with`] with `metakey` query like `Metakey::ContentLength | Metakey::LastModified` - /// so that we can avoid extra requests. + /// For fetch metadata of entries returned by [`BlockingLister`], it's better to + /// use [`BlockingOperator::list_with`] and [`BlockingOperator::lister_with`] with `metakey` + /// query like `Metakey::ContentLength | Metakey::LastModified` so that we can avoid extra requests. /// /// # Behavior /// @@ -200,8 +200,9 @@ impl BlockingOperator { /// /// # Notes /// - /// For fetch metadata of entries returned by [`Lister`], it's better to use [`list_with`] and - /// [`lister_with`] with `metakey` query like `Metakey::ContentLength | Metakey::LastModified` + /// For fetch metadata of entries returned by [`Lister`], it's better to use + /// [`Operator::list_with`] and [`Operator::lister_with`] with `metakey` query like + /// `Metakey::ContentLength | Metakey::LastModified` /// so that we can avoid extra requests. /// /// # Behavior diff --git a/core/src/types/operator/operator.rs b/core/src/types/operator/operator.rs index 0a9c56abd5f..036e29ab586 100644 --- a/core/src/types/operator/operator.rs +++ b/core/src/types/operator/operator.rs @@ -35,11 +35,12 @@ use crate::*; /// We will usually do some general checks and data transformations in this layer, /// like normalizing path from input, checking whether the path refers to one file or one directory, /// and so on. -/// Read [`Operator::concepts`][docs::concepts] for more about [`Operator::Operator`]. +/// +/// Read [`concepts`][crate::docs::concepts] for more about [`Operator`]. /// /// # Examples /// -/// Read more backend init examples in [`Operator::services`] +/// Read more backend init examples in [`services`] /// /// ``` /// # use anyhow::Result; @@ -182,7 +183,7 @@ impl Operator { /// /// ## Reuse Metadata /// - /// For fetch metadata of entries returned by [`Operator::Lister`], it's better to use + /// For fetch metadata of entries returned by [`Lister`], it's better to use /// [`Operator::list_with`] and [`Operator::lister_with`] with `metakey` query like /// `Metakey::ContentLength | Metakey::LastModified` so that we can avoid extra stat requests. /// @@ -215,7 +216,7 @@ impl Operator { /// /// ## Reuse Metadata /// - /// For fetch metadata of entries returned by [`Operator::Lister`], it's better to use + /// For fetch metadata of entries returned by [`Lister`], it's better to use /// [`Operator::list_with`] and [`Operator::lister_with`] with `metakey` query like /// `Metakey::ContentLength | Metakey::LastModified` so that we can avoid extra requests. /// @@ -1700,8 +1701,8 @@ impl Operator { /// List entries that starts with given `path` in parent dir. /// - /// This function will create a new [`Operator::Lister`] to list entries. Users can stop - /// listing via dropping this [`Operator::Lister`]. + /// This function will create a new [`Lister`] to list entries. Users can stop + /// listing via dropping this [`Lister`]. /// /// # Notes /// @@ -1747,8 +1748,8 @@ impl Operator { /// List entries that starts with given `path` in parent dir with options. /// - /// This function will create a new [`Operator::Lister`] to list entries. Users can stop listing via - /// dropping this [`Operator::Lister`]. + /// This function will create a new [`Lister`] to list entries. Users can stop listing via + /// dropping this [`Lister`]. /// /// # Options /// diff --git a/core/src/types/read/reader.rs b/core/src/types/read/reader.rs index 9ecf5f83240..59d36c38294 100644 --- a/core/src/types/read/reader.rs +++ b/core/src/types/read/reader.rs @@ -35,9 +35,53 @@ use crate::*; /// [`Reader`] provides multiple ways to read data from given reader. Please note that it's /// undefined behavior to use `Reader` in different ways. /// +/// `Reader` implements `Clone` so you can clone it and store in place where ever you want. +/// /// ## Direct /// -/// [`Reader`] provides public API including [`Reader::read`], [`Reader:read_range`], and [`Reader::read_to_end`]. You can use those APIs directly without extra copy. +/// [`Reader`] provides public API including [`Reader::read`]. You can use those APIs directly without extra copy. +/// +/// ``` +/// use opendal::Operator; +/// use opendal::Result; +/// +/// async fn test(op: Operator) -> Result<()> { +/// let r = op.reader("path/to/file").await?; +/// let bs = r.read(0..1024).await?; +/// Ok(()) +/// } +/// ``` +/// +/// ## Read like `Stream` +/// +/// ``` +/// use opendal::Operator; +/// use anyhow::Result; +/// use futures::TryStreamExt; +/// use bytes::Bytes; +/// +/// async fn test(op: Operator) -> Result<()> { +/// let s = op.reader("path/to/file").await?.into_bytes_stream(1024..2048).await?; +/// let bs: Vec = s.try_collect().await?; +/// Ok(()) +/// } +/// ``` +/// +/// ## Read like `AsyncRead` and `AsyncBufRead` +/// +/// ``` +/// use opendal::Operator; +/// use anyhow::Result; +/// use futures::AsyncReadExt; +/// use bytes::Bytes; +/// +/// async fn test(op: Operator) -> Result<()> { +/// let mut r = op.reader("path/to/file").await?.into_futures_async_read(1024..2048).await?; +/// let mut bs = vec![]; +/// let n = r.read_to_end(&mut bs).await?; +/// Ok(()) +/// } +/// ``` #[derive(Clone)] pub struct Reader { ctx: Arc, @@ -95,7 +139,7 @@ impl Reader { /// Read give range from reader into [`Buffer`]. /// - /// This operation is zero-copy, which means it keeps the [`Bytes`] returned by underlying + /// This operation is zero-copy, which means it keeps the [`bytes::Bytes`] returned by underlying /// storage services without any extra copy or intensive memory allocations. pub async fn read(&self, range: impl RangeBounds) -> Result { let bufs: Vec<_> = self.clone().into_stream(range).await?.try_collect().await?; diff --git a/core/src/types/scheme.rs b/core/src/types/scheme.rs index ab5cf520027..5a3e74fe851 100644 --- a/core/src/types/scheme.rs +++ b/core/src/types/scheme.rs @@ -88,7 +88,7 @@ pub enum Scheme { Http, /// [huggingface][crate::services::Huggingface]: Huggingface services. Huggingface, - /// [alluxio][created::services::Alluxio]: Alluxio services. + /// [alluxio][crate::services::Alluxio]: Alluxio services. Alluxio, /// [ipmfs][crate::services::Ipfs]: IPFS HTTP Gateway @@ -147,19 +147,19 @@ pub enum Scheme { Webhdfs, /// [redb][crate::services::Redb]: Redb Services Redb, - /// [tikv][crate::services::tikv]: Tikv Services + /// [tikv][crate::services::Tikv]: Tikv Services Tikv, - /// [azfile][crate::services::azfile]: Azfile Services + /// [azfile][crate::services::Azfile]: Azfile Services Azfile, - /// [mongodb](crate::services::mongodb): MongoDB Services + /// [mongodb](crate::services::Mongodb): MongoDB Services Mongodb, - /// [gridfs](crate::services::gridfs): MongoDB Gridfs Services + /// [gridfs](crate::services::Gridfs): MongoDB Gridfs Services Gridfs, /// [Github Contents][crate::services::Github]: Github contents support. Github, - /// [Native HDFS](crate::services::hdfs_native): Hdfs Native service, using rust hdfs-native client for hdfs + /// [Native HDFS](crate::services::HdfsNative): Hdfs Native service, using rust hdfs-native client for hdfs HdfsNative, - /// [surrealdb](crate::services::surrealdb): Surrealdb Services + /// [surrealdb](crate::services::Surrealdb): Surrealdb Services Surrealdb, /// Custom that allow users to implement services outside of OpenDAL. /// diff --git a/core/src/types/write/buffer_sink.rs b/core/src/types/write/buffer_sink.rs index f6115a6c683..eba169bb487 100644 --- a/core/src/types/write/buffer_sink.rs +++ b/core/src/types/write/buffer_sink.rs @@ -21,9 +21,9 @@ use bytes::Buf; use std::pin::Pin; use std::task::{ready, Context, Poll}; -/// BufferSink is the adapter of [`Sink`] generated by [`Writer`]. +/// BufferSink is the adapter of [`futures::Sink`] generated by [`Writer`]. /// -/// Users can use this adapter in cases where they need to use [`Sink`] +/// Users can use this adapter in cases where they need to use [`futures::Sink`] pub struct BufferSink { state: State, buf: Buffer, diff --git a/core/src/types/write/futures_bytes_sink.rs b/core/src/types/write/futures_bytes_sink.rs index 67a7dfd50cd..383998cfae4 100644 --- a/core/src/types/write/futures_bytes_sink.rs +++ b/core/src/types/write/futures_bytes_sink.rs @@ -22,9 +22,9 @@ use futures::SinkExt; use std::pin::Pin; use std::task::{Context, Poll}; -/// FuturesBytesSink is the adapter of [`Sink`] generated by [`Writer::into_bytes_sink`]. +/// FuturesBytesSink is the adapter of [`futures::Sink`] generated by [`Writer::into_bytes_sink`]. /// -/// Users can use this adapter in cases where they need to use [`Sink`] trait. FuturesBytesSink +/// Users can use this adapter in cases where they need to use [`futures::Sink`] trait. FuturesBytesSink /// reuses the same concurrent and chunk settings from [`Writer`]. /// /// FuturesBytesSink also implements [`Unpin`], [`Send`] and [`Sync`]. diff --git a/core/src/types/write/writer.rs b/core/src/types/write/writer.rs index 80de47e41b9..974e9f4c1b0 100644 --- a/core/src/types/write/writer.rs +++ b/core/src/types/write/writer.rs @@ -37,16 +37,50 @@ use crate::*; /// support write multiple chunks will return [`ErrorKind::Unsupported`] error when calling `write` /// at the second time. /// -/// ```no_build -/// let mut w = op.writer("path/to/file").await?; -/// w.write(bs).await?; -/// w.write(bs).await?; -/// w.close().await? /// ``` +/// use opendal::Operator; +/// use opendal::Result; /// -/// Our writer also provides [`Writer::sink`] and [`Writer::copy`] support. +/// async fn test(op: Operator) -> Result<()> { +/// let mut w = op.writer("path/to/file").await?; +/// w.write(vec![1;1024]).await?; +/// w.write(vec![2;1024]).await?; +/// w.close().await?; +/// Ok(()) +/// } +/// ``` +/// +/// ### Write like `Sink` +/// +/// ``` +/// use futures::SinkExt; +/// use opendal::Operator; +/// use anyhow::Result; +/// +/// async fn test(op: Operator) -> Result<()> { +/// let mut w = op.writer("path/to/file").await?.into_bytes_sink(); +/// w.send(vec![1;1024].into()).await?; +/// w.send(vec![2;1024].into()).await?; +/// w.close().await?; +/// Ok(()) +/// } +/// ``` +/// +/// ### Write like `AsyncWrite` /// -/// Besides, our writer implements [`AsyncWrite`] and [`tokio::io::AsyncWrite`]. +/// ``` +/// use futures::AsyncWriteExt; +/// use opendal::Operator; +/// use anyhow::Result; +/// +/// async fn test(op: Operator) -> Result<()> { +/// let mut w = op.writer("path/to/file").await?.into_futures_async_write(); +/// w.write(&vec![1;1024]).await?; +/// w.write(&vec![2;1024]).await?; +/// w.close().await?; +/// Ok(()) +/// } +/// ``` /// /// ### Write with append enabled /// From 69b10ef198403de69086428e6ef5b99bd2493883 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 5 Jun 2024 22:27:49 +0800 Subject: [PATCH 2/3] Format code Signed-off-by: Xuanwo --- bin/ofs/src/bin/ofs.rs | 7 ++- bin/ofs/src/fuse/adapter.rs | 2 - bin/ofs/src/fuse/mod.rs | 9 ++-- bin/ofs/tests/common/mod.rs | 3 +- bin/ofs/tests/file.rs | 16 ++++--- bin/ofs/tests/path.rs | 1 - bin/oli/src/commands/cp.rs | 3 +- bin/ovfs/src/virtiofs.rs | 18 ++++--- bin/ovfs/src/virtiofs_utils.rs | 21 ++++++--- bindings/c/src/reader.rs | 3 +- bindings/c/src/types.rs | 3 +- bindings/cpp/src/reader.rs | 4 +- bindings/java/src/async_operator.rs | 4 +- bindings/java/src/executor.rs | 6 ++- bindings/java/src/lib.rs | 1 - bindings/java/src/operator.rs | 1 - bindings/java/src/operator_input_stream.rs | 14 ++++-- bindings/java/src/operator_output_stream.rs | 8 ++-- bindings/nodejs/src/lib.rs | 3 +- bindings/python/src/file.rs | 6 ++- core/benches/types/concurrent_tasks.rs | 4 +- core/src/layers/prometheus.rs | 3 +- core/src/layers/prometheus_client.rs | 3 +- core/src/layers/retry.rs | 2 +- core/src/raw/adapters/kv/api.rs | 3 +- core/src/raw/adapters/typed_kv/api.rs | 6 ++- core/src/raw/atomic_util.rs | 3 +- core/src/raw/futures_util.rs | 6 ++- core/src/raw/http_util/body.rs | 3 +- core/src/raw/layer.rs | 1 - core/src/raw/oio/buf/pooled_buf.rs | 3 +- core/src/raw/oio/write/multipart_write.rs | 3 +- core/src/services/aliyun_drive/backend.rs | 3 +- core/src/services/aliyun_drive/core.rs | 12 +++-- core/src/services/aliyun_drive/lister.rs | 10 ++-- core/src/services/aliyun_drive/writer.rs | 13 +++-- core/src/services/compfs/backend.rs | 6 +-- core/src/services/compfs/core.rs | 18 ++++--- core/src/services/fs/core.rs | 4 +- core/src/services/fs/reader.rs | 1 + core/src/services/ftp/backend.rs | 1 - core/src/services/ftp/reader.rs | 3 +- core/src/services/hdfs/reader.rs | 7 +-- core/src/services/s3/backend.rs | 3 +- core/src/services/sftp/reader.rs | 1 - core/src/services/supabase/backend.rs | 3 +- .../types/blocking_read/buffer_iterator.rs | 5 +- .../types/blocking_read/std_bytes_iterator.rs | 3 +- .../types/blocking_write/blocking_writer.rs | 3 +- core/src/types/blocking_write/std_writer.rs | 3 +- core/src/types/buffer.rs | 1 - core/src/types/context.rs | 11 +++-- core/src/types/execute/api.rs | 11 +++-- core/src/types/execute/executor.rs | 12 +++-- .../types/execute/executors/tokio_executor.rs | 9 ++-- core/src/types/operator/operator.rs | 5 +- core/src/types/read/buffer_stream.rs | 10 ++-- core/src/types/read/reader.rs | 35 ++++++++++---- core/src/types/write/buffer_sink.rs | 10 ++-- core/src/types/write/futures_async_writer.rs | 3 +- core/src/types/write/futures_bytes_sink.rs | 11 +++-- core/src/types/write/writer.rs | 47 +++++++++---------- core/tests/behavior/async_delete.rs | 3 +- integrations/object_store/src/send_wrapper.rs | 15 +++--- 64 files changed, 279 insertions(+), 176 deletions(-) diff --git a/bin/ofs/src/bin/ofs.rs b/bin/ofs/src/bin/ofs.rs index 44b2d298e20..0a9c862cd15 100644 --- a/bin/ofs/src/bin/ofs.rs +++ b/bin/ofs/src/bin/ofs.rs @@ -43,11 +43,14 @@ async fn main() -> Result<()> { #[cfg(any(target_os = "linux", target_os = "freebsd"))] async fn execute(cfg: Config) -> Result<()> { - use std::{collections::HashMap, env, str::FromStr}; + use std::collections::HashMap; + use std::env; + use std::str::FromStr; use anyhow::anyhow; use ofs::fuse::Fuse; - use opendal::{Operator, Scheme}; + use opendal::Operator; + use opendal::Scheme; if cfg.backend.has_host() { log::warn!("backend host will be ignored"); diff --git a/bin/ofs/src/fuse/adapter.rs b/bin/ofs/src/fuse/adapter.rs index 5c14c767ea0..ddccf08ab4e 100644 --- a/bin/ofs/src/fuse/adapter.rs +++ b/bin/ofs/src/fuse/adapter.rs @@ -24,14 +24,12 @@ use std::time::Duration; use std::time::SystemTime; use bytes::Bytes; - use fuse3::path::prelude::*; use fuse3::Errno; use fuse3::Result; use futures_util::stream; use futures_util::stream::BoxStream; use futures_util::StreamExt; - use opendal::EntryMode; use opendal::ErrorKind; use opendal::Metadata; diff --git a/bin/ofs/src/fuse/mod.rs b/bin/ofs/src/fuse/mod.rs index 21f97148cba..a4998602d55 100644 --- a/bin/ofs/src/fuse/mod.rs +++ b/bin/ofs/src/fuse/mod.rs @@ -17,13 +17,14 @@ mod adapter; -use adapter::FuseAdapter; +use std::io; +use std::path::Path; +use adapter::FuseAdapter; +use fuse3::path::Session; pub use fuse3::raw::MountHandle; - -use fuse3::{path::Session, MountOptions}; +use fuse3::MountOptions; use opendal::Operator; -use std::{io, path::Path}; /// Ofs fuse filesystem mounter. #[derive(Debug, Clone)] diff --git a/bin/ofs/tests/common/mod.rs b/bin/ofs/tests/common/mod.rs index 8d6678c55c3..b78a0d2a3f3 100644 --- a/bin/ofs/tests/common/mod.rs +++ b/bin/ofs/tests/common/mod.rs @@ -21,7 +21,8 @@ use opendal::raw::tests; use opendal::Capability; use tempfile::TempDir; use test_context::TestContext; -use tokio::runtime::{self, Runtime}; +use tokio::runtime::Runtime; +use tokio::runtime::{self}; static INIT_LOGGER: OnceLock<()> = OnceLock::new(); static RUNTIME: OnceLock = OnceLock::new(); diff --git a/bin/ofs/tests/file.rs b/bin/ofs/tests/file.rs index e6575e37697..6fdf6344f1e 100644 --- a/bin/ofs/tests/file.rs +++ b/bin/ofs/tests/file.rs @@ -17,15 +17,17 @@ mod common; -use std::{ - fs::{self, File, OpenOptions}, - io::{Read, Seek, SeekFrom, Write}, - thread, - time::Duration, -}; +use std::fs::File; +use std::fs::OpenOptions; +use std::fs::{self}; +use std::io::Read; +use std::io::Seek; +use std::io::SeekFrom; +use std::io::Write; +use std::thread; +use std::time::Duration; use common::OfsTestContext; - use test_context::test_context; static TEST_TEXT: &str = include_str!("../Cargo.toml"); diff --git a/bin/ofs/tests/path.rs b/bin/ofs/tests/path.rs index f8f72f559bc..0c5611b5978 100644 --- a/bin/ofs/tests/path.rs +++ b/bin/ofs/tests/path.rs @@ -20,7 +20,6 @@ mod common; use std::fs; use common::OfsTestContext; - use test_context::test_context; use walkdir::WalkDir; diff --git a/bin/oli/src/commands/cp.rs b/bin/oli/src/commands/cp.rs index 1ac27948a20..d8ea084df3b 100644 --- a/bin/oli/src/commands/cp.rs +++ b/bin/oli/src/commands/cp.rs @@ -24,7 +24,8 @@ use clap::Arg; use clap::ArgAction; use clap::ArgMatches; use clap::Command; -use futures::{AsyncWriteExt, TryStreamExt}; +use futures::AsyncWriteExt; +use futures::TryStreamExt; use crate::config::Config; diff --git a/bin/ovfs/src/virtiofs.rs b/bin/ovfs/src/virtiofs.rs index 28c616827f0..a7e33e22751 100644 --- a/bin/ovfs/src/virtiofs.rs +++ b/bin/ovfs/src/virtiofs.rs @@ -18,14 +18,20 @@ use std::io; use std::sync::RwLock; -use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures}; +use vhost::vhost_user::message::VhostUserProtocolFeatures; +use vhost::vhost_user::message::VhostUserVirtioFeatures; use vhost::vhost_user::Backend; -use vhost_user_backend::{VhostUserBackend, VringMutex, VringState, VringT}; +use vhost_user_backend::VhostUserBackend; +use vhost_user_backend::VringMutex; +use vhost_user_backend::VringState; +use vhost_user_backend::VringT; use virtio_bindings::bindings::virtio_config::VIRTIO_F_VERSION_1; -use virtio_bindings::bindings::virtio_ring::{ - VIRTIO_RING_F_EVENT_IDX, VIRTIO_RING_F_INDIRECT_DESC, -}; -use vm_memory::{ByteValued, GuestMemoryAtomic, GuestMemoryMmap, Le32}; +use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_EVENT_IDX; +use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_INDIRECT_DESC; +use vm_memory::ByteValued; +use vm_memory::GuestMemoryAtomic; +use vm_memory::GuestMemoryMmap; +use vm_memory::Le32; use vmm_sys_util::epoll::EventSet; use vmm_sys_util::eventfd::EventFd; diff --git a/bin/ovfs/src/virtiofs_utils.rs b/bin/ovfs/src/virtiofs_utils.rs index e98bbd297fe..f797c8dacb4 100644 --- a/bin/ovfs/src/virtiofs_utils.rs +++ b/bin/ovfs/src/virtiofs_utils.rs @@ -17,17 +17,24 @@ use std::cmp::min; use std::collections::VecDeque; -use std::io::{self, Read, Write}; -use std::mem::{size_of, MaybeUninit}; +use std::io::Read; +use std::io::Write; +use std::io::{self}; +use std::mem::size_of; +use std::mem::MaybeUninit; use std::ops::Deref; use std::ptr::copy_nonoverlapping; use virtio_queue::DescriptorChain; -use vm_memory::bitmap::{Bitmap, BitmapSlice}; -use vm_memory::{ - Address, ByteValued, GuestMemory, GuestMemoryMmap, GuestMemoryRegion, VolatileMemory, - VolatileSlice, -}; +use vm_memory::bitmap::Bitmap; +use vm_memory::bitmap::BitmapSlice; +use vm_memory::Address; +use vm_memory::ByteValued; +use vm_memory::GuestMemory; +use vm_memory::GuestMemoryMmap; +use vm_memory::GuestMemoryRegion; +use vm_memory::VolatileMemory; +use vm_memory::VolatileSlice; use crate::error::*; diff --git a/bindings/c/src/reader.rs b/bindings/c/src/reader.rs index 398365ffff0..40007f99901 100644 --- a/bindings/c/src/reader.rs +++ b/bindings/c/src/reader.rs @@ -15,9 +15,10 @@ // specific language governing permissions and limitations // under the License. -use ::opendal as core; use std::io::Read; +use ::opendal as core; + use super::*; /// \brief The result type returned by opendal's reader operation. diff --git a/bindings/c/src/types.rs b/bindings/c/src/types.rs index 049f92f8ce7..26d7f29ffb9 100644 --- a/bindings/c/src/types.rs +++ b/bindings/c/src/types.rs @@ -15,10 +15,11 @@ // specific language governing permissions and limitations // under the License. -use opendal::Buffer; use std::collections::HashMap; use std::os::raw::c_char; +use opendal::Buffer; + /// \brief opendal_bytes carries raw-bytes with its length /// /// The opendal_bytes type is a C-compatible substitute for Vec type diff --git a/bindings/cpp/src/reader.rs b/bindings/cpp/src/reader.rs index 0094d460004..00d4ad862b9 100644 --- a/bindings/cpp/src/reader.rs +++ b/bindings/cpp/src/reader.rs @@ -15,9 +15,11 @@ // specific language governing permissions and limitations // under the License. +use std::io::Read; +use std::io::Seek; + use anyhow::Result; use opendal as od; -use std::io::{Read, Seek}; use super::ffi; diff --git a/bindings/java/src/async_operator.rs b/bindings/java/src/async_operator.rs index 69b5a3f4837..d7b2ed77a1e 100644 --- a/bindings/java/src/async_operator.rs +++ b/bindings/java/src/async_operator.rs @@ -35,7 +35,9 @@ use opendal::Scheme; use crate::convert::jmap_to_hashmap; use crate::convert::jstring_to_string; -use crate::executor::{executor_or_default, get_current_env, Executor}; +use crate::executor::executor_or_default; +use crate::executor::get_current_env; +use crate::executor::Executor; use crate::make_entry; use crate::make_metadata; use crate::make_operator_info; diff --git a/bindings/java/src/executor.rs b/bindings/java/src/executor.rs index 6bda868fa35..4c423b06bed 100644 --- a/bindings/java/src/executor.rs +++ b/bindings/java/src/executor.rs @@ -19,9 +19,11 @@ use std::cell::RefCell; use std::ffi::c_void; use std::future::Future; -use jni::objects::{JClass, JObject}; +use jni::objects::JClass; +use jni::objects::JObject; use jni::sys::jlong; -use jni::{JNIEnv, JavaVM}; +use jni::JNIEnv; +use jni::JavaVM; use once_cell::sync::OnceCell; use tokio::task::JoinHandle; diff --git a/bindings/java/src/lib.rs b/bindings/java/src/lib.rs index 64fffcab3a3..a7a67334b05 100644 --- a/bindings/java/src/lib.rs +++ b/bindings/java/src/lib.rs @@ -23,7 +23,6 @@ use jni::sys::jboolean; use jni::sys::jint; use jni::sys::jlong; use jni::JNIEnv; - use opendal::raw::PresignedRequest; use opendal::Capability; use opendal::Entry; diff --git a/bindings/java/src/operator.rs b/bindings/java/src/operator.rs index e128f82bd8c..9dfe74b0c78 100644 --- a/bindings/java/src/operator.rs +++ b/bindings/java/src/operator.rs @@ -25,7 +25,6 @@ use jni::sys::jobject; use jni::sys::jobjectArray; use jni::sys::jsize; use jni::JNIEnv; - use opendal::BlockingOperator; use crate::convert::jstring_to_string; diff --git a/bindings/java/src/operator_input_stream.rs b/bindings/java/src/operator_input_stream.rs index 0e07d2382ce..7af8f31a30f 100644 --- a/bindings/java/src/operator_input_stream.rs +++ b/bindings/java/src/operator_input_stream.rs @@ -15,11 +15,17 @@ // specific language governing permissions and limitations // under the License. -use crate::convert::jstring_to_string; -use jni::objects::{JByteArray, JClass, JObject, JString}; -use jni::sys::{jbyteArray, jlong}; +use jni::objects::JByteArray; +use jni::objects::JClass; +use jni::objects::JObject; +use jni::objects::JString; +use jni::sys::jbyteArray; +use jni::sys::jlong; use jni::JNIEnv; -use opendal::{BlockingOperator, StdBytesIterator}; +use opendal::BlockingOperator; +use opendal::StdBytesIterator; + +use crate::convert::jstring_to_string; /// # Safety /// diff --git a/bindings/java/src/operator_output_stream.rs b/bindings/java/src/operator_output_stream.rs index 7478fe67af6..f0bc8ad20cc 100644 --- a/bindings/java/src/operator_output_stream.rs +++ b/bindings/java/src/operator_output_stream.rs @@ -15,11 +15,13 @@ // specific language governing permissions and limitations // under the License. -use jni::objects::{JByteArray, JClass, JString}; +use jni::objects::JByteArray; +use jni::objects::JClass; +use jni::objects::JString; use jni::sys::jlong; use jni::JNIEnv; - -use opendal::{BlockingOperator, BlockingWriter}; +use opendal::BlockingOperator; +use opendal::BlockingWriter; use crate::convert::jstring_to_string; diff --git a/bindings/nodejs/src/lib.rs b/bindings/nodejs/src/lib.rs index cc85c14d114..d50807e784a 100644 --- a/bindings/nodejs/src/lib.rs +++ b/bindings/nodejs/src/lib.rs @@ -26,7 +26,8 @@ use std::io::Read; use std::str::FromStr; use std::time::Duration; -use futures::{AsyncReadExt, TryStreamExt}; +use futures::AsyncReadExt; +use futures::TryStreamExt; use napi::bindgen_prelude::*; #[napi] diff --git a/bindings/python/src/file.rs b/bindings/python/src/file.rs index 327d2055eea..0134bf8edcd 100644 --- a/bindings/python/src/file.rs +++ b/bindings/python/src/file.rs @@ -25,9 +25,11 @@ use std::io::Write; use std::ops::DerefMut; use std::sync::Arc; -use futures::{AsyncReadExt, AsyncSeekExt}; +use futures::AsyncReadExt; +use futures::AsyncSeekExt; use pyo3::buffer::PyBuffer; -use pyo3::exceptions::{PyIOError, PyValueError}; +use pyo3::exceptions::PyIOError; +use pyo3::exceptions::PyValueError; use pyo3::prelude::*; use pyo3_asyncio::tokio::future_into_py; use tokio::sync::Mutex; diff --git a/core/benches/types/concurrent_tasks.rs b/core/benches/types/concurrent_tasks.rs index ec691d95f5d..ca1dfeec551 100644 --- a/core/benches/types/concurrent_tasks.rs +++ b/core/benches/types/concurrent_tasks.rs @@ -15,7 +15,9 @@ // specific language governing permissions and limitations // under the License. -use criterion::{black_box, BatchSize, Criterion}; +use criterion::black_box; +use criterion::BatchSize; +use criterion::Criterion; use once_cell::sync::Lazy; use opendal::raw::ConcurrentTasks; use opendal::Executor; diff --git a/core/src/layers/prometheus.rs b/core/src/layers/prometheus.rs index 6c93ba1d387..ee740d55c42 100644 --- a/core/src/layers/prometheus.rs +++ b/core/src/layers/prometheus.rs @@ -31,7 +31,8 @@ use prometheus::register_int_counter_vec_with_registry; use prometheus::HistogramVec; use prometheus::Registry; -use crate::raw::oio::{ReadOperation, WriteOperation}; +use crate::raw::oio::ReadOperation; +use crate::raw::oio::WriteOperation; use crate::raw::Access; use crate::raw::*; use crate::*; diff --git a/core/src/layers/prometheus_client.rs b/core/src/layers/prometheus_client.rs index 25d27456e35..463e4092750 100644 --- a/core/src/layers/prometheus_client.rs +++ b/core/src/layers/prometheus_client.rs @@ -29,7 +29,8 @@ use prometheus_client::metrics::histogram; use prometheus_client::metrics::histogram::Histogram; use prometheus_client::registry::Registry; -use crate::raw::oio::{ReadOperation, WriteOperation}; +use crate::raw::oio::ReadOperation; +use crate::raw::oio::WriteOperation; use crate::raw::Access; use crate::raw::*; use crate::*; diff --git a/core/src/layers/retry.rs b/core/src/layers/retry.rs index 44df4fa1d42..e16e06ced24 100644 --- a/core/src/layers/retry.rs +++ b/core/src/layers/retry.rs @@ -741,12 +741,12 @@ mod tests { use std::sync::Arc; use std::sync::Mutex; - use crate::layers::LoggingLayer; use bytes::Bytes; use futures::TryStreamExt; use tracing_subscriber::filter::LevelFilter; use super::*; + use crate::layers::LoggingLayer; #[derive(Default, Clone)] struct MockBuilder { diff --git a/core/src/raw/adapters/kv/api.rs b/core/src/raw/adapters/kv/api.rs index c8f8704ba65..acf449d58bd 100644 --- a/core/src/raw/adapters/kv/api.rs +++ b/core/src/raw/adapters/kv/api.rs @@ -15,7 +15,8 @@ // specific language governing permissions and limitations // under the License. -use std::{fmt::Debug, future::ready}; +use std::fmt::Debug; +use std::future::ready; use futures::Future; diff --git a/core/src/raw/adapters/typed_kv/api.rs b/core/src/raw/adapters/typed_kv/api.rs index 8f4b62d7df9..9a0949df569 100644 --- a/core/src/raw/adapters/typed_kv/api.rs +++ b/core/src/raw/adapters/typed_kv/api.rs @@ -15,19 +15,21 @@ // specific language governing permissions and limitations // under the License. +use std::fmt::Debug; +use std::future::ready; use std::future::Future; use std::mem::size_of; -use std::{fmt::Debug, future::ready}; use chrono::Utc; +use crate::raw::MaybeSend; +use crate::Buffer; use crate::EntryMode; use crate::Error; use crate::ErrorKind; use crate::Metadata; use crate::Result; use crate::Scheme; -use crate::{raw::MaybeSend, Buffer}; /// Adapter is the typed adapter to underlying kv services. /// diff --git a/core/src/raw/atomic_util.rs b/core/src/raw/atomic_util.rs index 4876dc7651a..76b69319177 100644 --- a/core/src/raw/atomic_util.rs +++ b/core/src/raw/atomic_util.rs @@ -15,7 +15,8 @@ // specific language governing permissions and limitations // under the License. -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; /// AtomicContentLength is a wrapper of AtomicU64 that used to store content length. /// diff --git a/core/src/raw/futures_util.rs b/core/src/raw/futures_util.rs index 8a909b4f5bb..9ffac3c2f00 100644 --- a/core/src/raw/futures_util.rs +++ b/core/src/raw/futures_util.rs @@ -21,10 +21,12 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; -use crate::*; +use futures::poll; use futures::stream::FuturesOrdered; +use futures::FutureExt; use futures::StreamExt; -use futures::{poll, FutureExt}; + +use crate::*; /// BoxedFuture is the type alias of [`futures::future::BoxFuture`]. /// diff --git a/core/src/raw/http_util/body.rs b/core/src/raw/http_util/body.rs index 2db622f6e25..0e3e68c8bbb 100644 --- a/core/src/raw/http_util/body.rs +++ b/core/src/raw/http_util/body.rs @@ -17,7 +17,8 @@ use std::cmp::Ordering; -use futures::{Stream, StreamExt}; +use futures::Stream; +use futures::StreamExt; use oio::Read; use crate::raw::*; diff --git a/core/src/raw/layer.rs b/core/src/raw/layer.rs index f4391be878f..aade6c3d34f 100644 --- a/core/src/raw/layer.rs +++ b/core/src/raw/layer.rs @@ -44,7 +44,6 @@ use crate::*; /// ``` /// use std::sync::Arc; /// -/// /// use opendal::raw::*; /// use opendal::*; /// diff --git a/core/src/raw/oio/buf/pooled_buf.rs b/core/src/raw/oio/buf/pooled_buf.rs index 0f8d59a816a..86d97afdb0b 100644 --- a/core/src/raw/oio/buf/pooled_buf.rs +++ b/core/src/raw/oio/buf/pooled_buf.rs @@ -17,7 +17,8 @@ use std::collections::VecDeque; use std::fmt::Debug; -use std::fmt::{self, Formatter}; +use std::fmt::Formatter; +use std::fmt::{self}; use std::sync::Mutex; use bytes::BytesMut; diff --git a/core/src/raw/oio/write/multipart_write.rs b/core/src/raw/oio/write/multipart_write.rs index 0f0963de014..072b5f39b4f 100644 --- a/core/src/raw/oio/write/multipart_write.rs +++ b/core/src/raw/oio/write/multipart_write.rs @@ -17,8 +17,9 @@ use std::sync::Arc; +use futures::select; +use futures::Future; use futures::FutureExt; -use futures::{select, Future}; use crate::raw::*; use crate::*; diff --git a/core/src/services/aliyun_drive/backend.rs b/core/src/services/aliyun_drive/backend.rs index 091d0bc47ae..cb414ed8779 100644 --- a/core/src/services/aliyun_drive/backend.rs +++ b/core/src/services/aliyun_drive/backend.rs @@ -33,7 +33,8 @@ use super::core::*; use super::error::parse_error; use super::lister::AliyunDriveLister; use super::lister::AliyunDriveParent; -use super::writer::{AliyunDriveWriter, AliyunDriveWriters}; +use super::writer::AliyunDriveWriter; +use super::writer::AliyunDriveWriters; use crate::raw::*; use crate::*; diff --git a/core/src/services/aliyun_drive/core.rs b/core/src/services/aliyun_drive/core.rs index 5a7c0148fad..1fe56657db8 100644 --- a/core/src/services/aliyun_drive/core.rs +++ b/core/src/services/aliyun_drive/core.rs @@ -20,16 +20,18 @@ use std::sync::Arc; use bytes::Buf; use chrono::Utc; -use http::header::{self, HeaderValue}; -use http::{Method, Request}; -use serde::{Deserialize, Serialize}; +use http::header::HeaderValue; +use http::header::{self}; +use http::Method; +use http::Request; +use serde::Deserialize; +use serde::Serialize; use tokio::sync::Mutex; +use super::error::parse_error; use crate::raw::*; use crate::*; -use super::error::parse_error; - /// Available Aliyun Drive Type. #[derive(Debug, Deserialize, Default, Clone)] pub enum DriveType { diff --git a/core/src/services/aliyun_drive/lister.rs b/core/src/services/aliyun_drive/lister.rs index fa59f792960..5d0277e3d70 100644 --- a/core/src/services/aliyun_drive/lister.rs +++ b/core/src/services/aliyun_drive/lister.rs @@ -20,6 +20,10 @@ use std::sync::Arc; use bytes::Buf; use chrono::Utc; +use self::oio::Entry; +use super::core::AliyunDriveCore; +use super::core::AliyunDriveFile; +use super::core::AliyunDriveFileList; use crate::raw::*; use crate::EntryMode; use crate::Error; @@ -27,12 +31,6 @@ use crate::ErrorKind; use crate::Metadata; use crate::Result; -use self::oio::Entry; - -use super::core::AliyunDriveCore; -use super::core::AliyunDriveFile; -use super::core::AliyunDriveFileList; - pub struct AliyunDriveLister { core: Arc, diff --git a/core/src/services/aliyun_drive/writer.rs b/core/src/services/aliyun_drive/writer.rs index c6341708fe6..174c52a12c7 100644 --- a/core/src/services/aliyun_drive/writer.rs +++ b/core/src/services/aliyun_drive/writer.rs @@ -20,17 +20,20 @@ use std::sync::Arc; use base64::engine::general_purpose; use base64::Engine; use bytes::Buf; - -use md5::{Digest, Md5}; +use md5::Digest; +use md5::Md5; use sha1::Sha1; use tokio::sync::RwLock; +use super::core::AliyunDriveCore; +use super::core::RapidUpload; +use super::core::UploadUrlResponse; use crate::raw::*; -use crate::services::aliyun_drive::core::{CheckNameMode, CreateResponse, CreateType}; +use crate::services::aliyun_drive::core::CheckNameMode; +use crate::services::aliyun_drive::core::CreateResponse; +use crate::services::aliyun_drive::core::CreateType; use crate::*; -use super::core::{AliyunDriveCore, RapidUpload, UploadUrlResponse}; - pub type AliyunDriveWriters = oio::MultipartWriter; pub struct AliyunDriveWriter { diff --git a/core/src/services/compfs/backend.rs b/core/src/services/compfs/backend.rs index 7f9baba5b5b..fcfa7ba67f0 100644 --- a/core/src/services/compfs/backend.rs +++ b/core/src/services/compfs/backend.rs @@ -15,13 +15,13 @@ // specific language governing permissions and limitations // under the License. +use std::collections::HashMap; +use std::path::PathBuf; + use super::core::CompioThread; use crate::raw::*; use crate::*; -use std::collections::HashMap; -use std::path::PathBuf; - /// [`compio`]-based file system support. #[derive(Debug, Clone, Default)] pub struct CompfsBuilder { diff --git a/core/src/services/compfs/core.rs b/core/src/services/compfs/core.rs index b95db7c978a..e6a462402cb 100644 --- a/core/src/services/compfs/core.rs +++ b/core/src/services/compfs/core.rs @@ -15,14 +15,17 @@ // specific language governing permissions and limitations // under the License. +use std::future::Future; +use std::thread::JoinHandle; + use compio::buf::IoBuf; use compio::runtime::RuntimeBuilder; +use futures::channel::mpsc; use futures::channel::mpsc::SendError; -use futures::channel::{mpsc, oneshot}; +use futures::channel::oneshot; use futures::future::LocalBoxFuture; -use futures::{SinkExt, StreamExt}; -use std::future::Future; -use std::thread::JoinHandle; +use futures::SinkExt; +use futures::StreamExt; use crate::Buffer; @@ -167,9 +170,12 @@ unsafe impl IoBuf for Buffer { #[cfg(test)] mod tests { + use bytes::Buf; + use bytes::Bytes; + use rand::thread_rng; + use rand::Rng; + use super::*; - use bytes::{Buf, Bytes}; - use rand::{thread_rng, Rng}; fn setup_buffer() -> (Buffer, usize, Bytes) { let mut rng = thread_rng(); diff --git a/core/src/services/fs/core.rs b/core/src/services/fs/core.rs index 8580542dcff..3c63f78ecf3 100644 --- a/core/src/services/fs/core.rs +++ b/core/src/services/fs/core.rs @@ -15,11 +15,13 @@ // specific language governing permissions and limitations // under the License. +use std::path::Path; +use std::path::PathBuf; + use uuid::Uuid; use crate::raw::*; use crate::*; -use std::path::{Path, PathBuf}; #[derive(Debug)] pub struct FsCore { diff --git a/core/src/services/fs/reader.rs b/core/src/services/fs/reader.rs index 53059bfc028..1629e670dfb 100644 --- a/core/src/services/fs/reader.rs +++ b/core/src/services/fs/reader.rs @@ -17,6 +17,7 @@ use std::io::Read; use std::sync::Arc; + use tokio::io::AsyncReadExt; use tokio::io::ReadBuf; diff --git a/core/src/services/ftp/backend.rs b/core/src/services/ftp/backend.rs index 4dfb45e2903..f5b4112e665 100644 --- a/core/src/services/ftp/backend.rs +++ b/core/src/services/ftp/backend.rs @@ -22,7 +22,6 @@ use std::str; use std::str::FromStr; use async_tls::TlsConnector; - use bb8::PooledConnection; use bb8::RunError; use http::Uri; diff --git a/core/src/services/ftp/reader.rs b/core/src/services/ftp/reader.rs index 238a5538fe2..132ff62116a 100644 --- a/core/src/services/ftp/reader.rs +++ b/core/src/services/ftp/reader.rs @@ -17,7 +17,8 @@ use bb8::PooledConnection; use bytes::BytesMut; -use futures::{AsyncRead, AsyncReadExt}; +use futures::AsyncRead; +use futures::AsyncReadExt; use super::backend::Manager; use super::err::parse_error; diff --git a/core/src/services/hdfs/reader.rs b/core/src/services/hdfs/reader.rs index 32bad0a8c05..817e1316357 100644 --- a/core/src/services/hdfs/reader.rs +++ b/core/src/services/hdfs/reader.rs @@ -15,11 +15,12 @@ // specific language governing permissions and limitations // under the License. -use bytes::BytesMut; +use std::io::Read; +use bytes::BytesMut; use futures::AsyncReadExt; -use hdrs::{AsyncFile, File}; -use std::io::Read; +use hdrs::AsyncFile; +use hdrs::File; use tokio::io::ReadBuf; use crate::raw::*; diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index c9a18464358..d6edb1e7478 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -26,7 +26,8 @@ use std::sync::Arc; use base64::prelude::BASE64_STANDARD; use base64::Engine; use bytes::Buf; -use http::{Response, StatusCode}; +use http::Response; +use http::StatusCode; use log::debug; use log::warn; use md5::Digest; diff --git a/core/src/services/sftp/reader.rs b/core/src/services/sftp/reader.rs index e64dfeac032..f007c3bba64 100644 --- a/core/src/services/sftp/reader.rs +++ b/core/src/services/sftp/reader.rs @@ -16,7 +16,6 @@ // under the License. use bb8::PooledConnection; - use bytes::BytesMut; use openssh_sftp_client::file::File; diff --git a/core/src/services/supabase/backend.rs b/core/src/services/supabase/backend.rs index e38b46b8f8b..7f79fa083aa 100644 --- a/core/src/services/supabase/backend.rs +++ b/core/src/services/supabase/backend.rs @@ -18,7 +18,8 @@ use std::fmt::Debug; use std::sync::Arc; -use http::{Response, StatusCode}; +use http::Response; +use http::StatusCode; use log::debug; use super::core::*; diff --git a/core/src/types/blocking_read/buffer_iterator.rs b/core/src/types/blocking_read/buffer_iterator.rs index 8f5c770855f..91a98130cc4 100644 --- a/core/src/types/blocking_read/buffer_iterator.rs +++ b/core/src/types/blocking_read/buffer_iterator.rs @@ -15,11 +15,12 @@ // specific language governing permissions and limitations // under the License. +use std::ops::Range; +use std::sync::Arc; + use crate::raw::*; use crate::Buffer; use crate::*; -use std::ops::Range; -use std::sync::Arc; struct IteratingReader { generator: ReadGenerator, diff --git a/core/src/types/blocking_read/std_bytes_iterator.rs b/core/src/types/blocking_read/std_bytes_iterator.rs index 9aacb690ecb..23049dd6eec 100644 --- a/core/src/types/blocking_read/std_bytes_iterator.rs +++ b/core/src/types/blocking_read/std_bytes_iterator.rs @@ -19,10 +19,11 @@ use std::io; use std::ops::Range; use std::sync::Arc; -use crate::{Buffer, BufferIterator}; use bytes::Bytes; use crate::raw::*; +use crate::Buffer; +use crate::BufferIterator; use crate::*; /// StdIterator is the adapter of [`Iterator`] for [`BlockingReader`][crate::BlockingReader]. diff --git a/core/src/types/blocking_write/blocking_writer.rs b/core/src/types/blocking_write/blocking_writer.rs index dc83b1db94d..ccba96fd954 100644 --- a/core/src/types/blocking_write/blocking_writer.rs +++ b/core/src/types/blocking_write/blocking_writer.rs @@ -15,9 +15,10 @@ // specific language governing permissions and limitations // under the License. +use bytes::Buf; + use crate::raw::*; use crate::*; -use bytes::Buf; /// BlockingWriter is designed to write data into given path in an blocking /// manner. diff --git a/core/src/types/blocking_write/std_writer.rs b/core/src/types/blocking_write/std_writer.rs index add39ca0aea..bef579cdac1 100644 --- a/core/src/types/blocking_write/std_writer.rs +++ b/core/src/types/blocking_write/std_writer.rs @@ -15,10 +15,11 @@ // specific language governing permissions and limitations // under the License. +use std::io::Write; + use crate::raw::oio::BlockingWrite; use crate::raw::*; use crate::*; -use std::io::Write; /// StdWriter is the adapter of [`std::io::Write`] for [`BlockingWriter`]. /// diff --git a/core/src/types/buffer.rs b/core/src/types/buffer.rs index 27e7c8eed19..0bbb81b8ff2 100644 --- a/core/src/types/buffer.rs +++ b/core/src/types/buffer.rs @@ -108,7 +108,6 @@ use crate::*; /// buf.to_bytes() /// } /// ``` -/// #[derive(Clone)] pub struct Buffer(Inner); diff --git a/core/src/types/context.rs b/core/src/types/context.rs index f5c03c76f02..40336aa6767 100644 --- a/core/src/types/context.rs +++ b/core/src/types/context.rs @@ -15,11 +15,12 @@ // specific language governing permissions and limitations // under the License. -use crate::raw::*; -use crate::*; use std::ops::Range; use std::sync::Arc; +use crate::raw::*; +use crate::*; + /// ReadContext holds the immutable context for give read operation. pub struct ReadContext { /// The accessor to the storage services. @@ -145,10 +146,12 @@ impl ReadGenerator { #[cfg(test)] mod tests { - use super::*; - use bytes::Bytes; use std::collections::HashMap; + use bytes::Bytes; + + use super::*; + #[tokio::test] async fn test_next_reader() -> Result<()> { let op = Operator::via_map(Scheme::Memory, HashMap::default())?; diff --git a/core/src/types/execute/api.rs b/core/src/types/execute/api.rs index 52798b4bdf8..2317434cb8d 100644 --- a/core/src/types/execute/api.rs +++ b/core/src/types/execute/api.rs @@ -15,12 +15,15 @@ // specific language governing permissions and limitations // under the License. -use crate::raw::BoxedStaticFuture; -use futures::future::RemoteHandle; -use futures::FutureExt; use std::future::Future; use std::pin::Pin; -use std::task::{Context, Poll}; +use std::task::Context; +use std::task::Poll; + +use futures::future::RemoteHandle; +use futures::FutureExt; + +use crate::raw::BoxedStaticFuture; /// Execute trait is used to execute task in background. /// diff --git a/core/src/types/execute/executor.rs b/core/src/types/execute/executor.rs index 80f20427ad2..1a1b6911486 100644 --- a/core/src/types/execute/executor.rs +++ b/core/src/types/execute/executor.rs @@ -15,13 +15,17 @@ // specific language governing permissions and limitations // under the License. -use super::*; -use crate::raw::{BoxedStaticFuture, MaybeSend}; -use futures::FutureExt; -use std::fmt::{Debug, Formatter}; +use std::fmt::Debug; +use std::fmt::Formatter; use std::future::Future; use std::sync::Arc; +use futures::FutureExt; + +use super::*; +use crate::raw::BoxedStaticFuture; +use crate::raw::MaybeSend; + /// Executor that runs futures in background. /// /// Executor is created by users and used by opendal. So it's by design that Executor only diff --git a/core/src/types/execute/executors/tokio_executor.rs b/core/src/types/execute/executors/tokio_executor.rs index f6e0eb8373d..fb9b3b6643b 100644 --- a/core/src/types/execute/executors/tokio_executor.rs +++ b/core/src/types/execute/executors/tokio_executor.rs @@ -31,13 +31,16 @@ impl Execute for TokioExecutor { #[cfg(test)] mod tests { - use super::*; - use crate::Executor; - use std::sync::atomic::{AtomicBool, Ordering}; + use std::sync::atomic::AtomicBool; + use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; + use tokio::time::sleep; + use super::*; + use crate::Executor; + #[tokio::test] async fn test_tokio_executor() { let executor = Executor::with(TokioExecutor::default()); diff --git a/core/src/types/operator/operator.rs b/core/src/types/operator/operator.rs index 036e29ab586..fd42fe49ff6 100644 --- a/core/src/types/operator/operator.rs +++ b/core/src/types/operator/operator.rs @@ -646,7 +646,10 @@ impl Operator { /// # use opendal::Operator; /// # use opendal::Scheme; /// # async fn test(op: Operator) -> Result<()> { - /// let r = op.reader_with("path/to/file").chunk(4 * 1024 * 1024).await?; + /// let r = op + /// .reader_with("path/to/file") + /// .chunk(4 * 1024 * 1024) + /// .await?; /// # Ok(()) /// # } /// ``` diff --git a/core/src/types/read/buffer_stream.rs b/core/src/types/read/buffer_stream.rs index 669165ec706..1e037cc22c1 100644 --- a/core/src/types/read/buffer_stream.rs +++ b/core/src/types/read/buffer_stream.rs @@ -21,9 +21,10 @@ use std::sync::Arc; use std::task::Context; use std::task::Poll; -use crate::raw::oio::Read; -use futures::{ready, Stream}; +use futures::ready; +use futures::Stream; +use crate::raw::oio::Read; use crate::raw::*; use crate::*; @@ -188,12 +189,13 @@ impl Stream for BufferStream { #[cfg(test)] mod tests { + use std::collections::HashMap; + use std::sync::Arc; + use bytes::Buf; use bytes::Bytes; use futures::TryStreamExt; use pretty_assertions::assert_eq; - use std::collections::HashMap; - use std::sync::Arc; use super::*; diff --git a/core/src/types/read/reader.rs b/core/src/types/read/reader.rs index 59d36c38294..89505919e86 100644 --- a/core/src/types/read/reader.rs +++ b/core/src/types/read/reader.rs @@ -15,8 +15,9 @@ // specific language governing permissions and limitations // under the License. +use std::ops::Bound; +use std::ops::Range; use std::ops::RangeBounds; -use std::ops::{Bound, Range}; use std::sync::Arc; use bytes::BufMut; @@ -55,13 +56,17 @@ use crate::*; /// ## Read like `Stream` /// /// ``` -/// use opendal::Operator; /// use anyhow::Result; -/// use futures::TryStreamExt; /// use bytes::Bytes; +/// use futures::TryStreamExt; +/// use opendal::Operator; /// /// async fn test(op: Operator) -> Result<()> { -/// let s = op.reader("path/to/file").await?.into_bytes_stream(1024..2048).await?; +/// let s = op +/// .reader("path/to/file") +/// .await? +/// .into_bytes_stream(1024..2048) +/// .await?; /// let bs: Vec = s.try_collect().await?; /// Ok(()) /// } @@ -70,13 +75,17 @@ use crate::*; /// ## Read like `AsyncRead` and `AsyncBufRead` /// /// ``` -/// use opendal::Operator; /// use anyhow::Result; -/// use futures::AsyncReadExt; /// use bytes::Bytes; +/// use futures::AsyncReadExt; +/// use opendal::Operator; /// /// async fn test(op: Operator) -> Result<()> { -/// let mut r = op.reader("path/to/file").await?.into_futures_async_read(1024..2048).await?; +/// let mut r = op +/// .reader("path/to/file") +/// .await? +/// .into_futures_async_read(1024..2048) +/// .await?; /// let mut bs = vec![]; /// let n = r.read_to_end(&mut bs).await?; /// Ok(()) @@ -316,7 +325,11 @@ impl Reader { /// use opendal::Result; /// /// async fn test(op: Operator) -> io::Result<()> { - /// let mut s = op.reader("hello.txt").await?.into_bytes_stream(1024..2048).await?;; + /// let mut s = op + /// .reader("hello.txt") + /// .await? + /// .into_bytes_stream(1024..2048) + /// .await?; /// let bs: Vec = s.try_collect().await?; /// /// Ok(()) @@ -341,7 +354,8 @@ impl Reader { /// .concurrent(8) /// .chunk(256) /// .await? - /// .into_bytes_stream(1024..2048).await?; + /// .into_bytes_stream(1024..2048) + /// .await?; /// let bs: Vec = s.try_collect().await?; /// /// Ok(()) @@ -359,11 +373,12 @@ impl Reader { #[cfg(test)] mod tests { + use std::collections::HashMap; + use bytes::Bytes; use rand::rngs::ThreadRng; use rand::Rng; use rand::RngCore; - use std::collections::HashMap; use super::*; use crate::raw::MaybeSend; diff --git a/core/src/types/write/buffer_sink.rs b/core/src/types/write/buffer_sink.rs index eba169bb487..a2304167675 100644 --- a/core/src/types/write/buffer_sink.rs +++ b/core/src/types/write/buffer_sink.rs @@ -15,11 +15,15 @@ // specific language governing permissions and limitations // under the License. +use std::pin::Pin; +use std::task::ready; +use std::task::Context; +use std::task::Poll; + +use bytes::Buf; + use crate::raw::*; use crate::*; -use bytes::Buf; -use std::pin::Pin; -use std::task::{ready, Context, Poll}; /// BufferSink is the adapter of [`futures::Sink`] generated by [`Writer`]. /// diff --git a/core/src/types/write/futures_async_writer.rs b/core/src/types/write/futures_async_writer.rs index 47f6e0542fc..8e35db48a24 100644 --- a/core/src/types/write/futures_async_writer.rs +++ b/core/src/types/write/futures_async_writer.rs @@ -21,7 +21,8 @@ use std::task::ready; use std::task::Context; use std::task::Poll; -use futures::{AsyncWrite, SinkExt}; +use futures::AsyncWrite; +use futures::SinkExt; use crate::raw::*; use crate::*; diff --git a/core/src/types/write/futures_bytes_sink.rs b/core/src/types/write/futures_bytes_sink.rs index 383998cfae4..1643da212c9 100644 --- a/core/src/types/write/futures_bytes_sink.rs +++ b/core/src/types/write/futures_bytes_sink.rs @@ -15,12 +15,15 @@ // specific language governing permissions and limitations // under the License. -use crate::raw::*; -use crate::*; +use std::pin::Pin; +use std::task::Context; +use std::task::Poll; + use bytes::Bytes; use futures::SinkExt; -use std::pin::Pin; -use std::task::{Context, Poll}; + +use crate::raw::*; +use crate::*; /// FuturesBytesSink is the adapter of [`futures::Sink`] generated by [`Writer::into_bytes_sink`]. /// diff --git a/core/src/types/write/writer.rs b/core/src/types/write/writer.rs index 974e9f4c1b0..a378e56bf8d 100644 --- a/core/src/types/write/writer.rs +++ b/core/src/types/write/writer.rs @@ -43,8 +43,8 @@ use crate::*; /// /// async fn test(op: Operator) -> Result<()> { /// let mut w = op.writer("path/to/file").await?; -/// w.write(vec![1;1024]).await?; -/// w.write(vec![2;1024]).await?; +/// w.write(vec![1; 1024]).await?; +/// w.write(vec![2; 1024]).await?; /// w.close().await?; /// Ok(()) /// } @@ -53,14 +53,14 @@ use crate::*; /// ### Write like `Sink` /// /// ``` +/// use anyhow::Result; /// use futures::SinkExt; /// use opendal::Operator; -/// use anyhow::Result; /// /// async fn test(op: Operator) -> Result<()> { /// let mut w = op.writer("path/to/file").await?.into_bytes_sink(); -/// w.send(vec![1;1024].into()).await?; -/// w.send(vec![2;1024].into()).await?; +/// w.send(vec![1; 1024].into()).await?; +/// w.send(vec![2; 1024].into()).await?; /// w.close().await?; /// Ok(()) /// } @@ -69,14 +69,14 @@ use crate::*; /// ### Write like `AsyncWrite` /// /// ``` +/// use anyhow::Result; /// use futures::AsyncWriteExt; /// use opendal::Operator; -/// use anyhow::Result; /// /// async fn test(op: Operator) -> Result<()> { /// let mut w = op.writer("path/to/file").await?.into_futures_async_write(); -/// w.write(&vec![1;1024]).await?; -/// w.write(&vec![2;1024]).await?; +/// w.write(&vec![1; 1024]).await?; +/// w.write(&vec![2; 1024]).await?; /// w.close().await?; /// Ok(()) /// } @@ -126,18 +126,17 @@ impl Writer { /// ## Examples /// /// ``` + /// use bytes::Bytes; /// use opendal::Operator; /// use opendal::Result; - /// use bytes::Bytes; /// /// async fn test(op: Operator) -> Result<()> { - /// let mut w = op - /// .writer("hello.txt") - /// .await?; + /// let mut w = op.writer("hello.txt").await?; /// // Buffer can be created from continues bytes. /// w.write("hello, world").await?; /// // Buffer can also be created from non-continues bytes. - /// w.write(vec![Bytes::from("hello,"), Bytes::from("world!")]).await?; + /// w.write(vec![Bytes::from("hello,"), Bytes::from("world!")]) + /// .await?; /// /// // Make sure file has been written completely. /// w.close().await?; @@ -213,10 +212,7 @@ impl Writer { /// use opendal::Result; /// /// async fn test(op: Operator) -> io::Result<()> { - /// let mut w = op - /// .writer("hello.txt") - /// .await? - /// .into_futures_async_write(); + /// let mut w = op.writer("hello.txt").await?.into_futures_async_write(); /// let bs = "Hello, World!".as_bytes(); /// w.write_all(bs).await?; /// w.close().await?; @@ -236,7 +232,9 @@ impl Writer { /// /// async fn test(op: Operator) -> io::Result<()> { /// let mut w = op - /// .writer_with("hello.txt").concurrent(8).chunk(256) + /// .writer_with("hello.txt") + /// .concurrent(8) + /// .chunk(256) /// .await? /// .into_futures_async_write(); /// let bs = "Hello, World!".as_bytes(); @@ -264,16 +262,13 @@ impl Writer { /// ``` /// use std::io; /// + /// use bytes::Bytes; /// use futures::SinkExt; /// use opendal::Operator; /// use opendal::Result; - /// use bytes::Bytes; /// /// async fn test(op: Operator) -> io::Result<()> { - /// let mut w = op - /// .writer("hello.txt") - /// .await? - /// .into_bytes_sink(); + /// let mut w = op.writer("hello.txt").await?.into_bytes_sink(); /// let bs = "Hello, World!".as_bytes(); /// w.send(Bytes::from(bs)).await?; /// w.close().await?; @@ -287,14 +282,16 @@ impl Writer { /// ``` /// use std::io; /// + /// use bytes::Bytes; /// use futures::SinkExt; /// use opendal::Operator; /// use opendal::Result; - /// use bytes::Bytes; /// /// async fn test(op: Operator) -> io::Result<()> { /// let mut w = op - /// .writer_with("hello.txt").concurrent(8).chunk(256) + /// .writer_with("hello.txt") + /// .concurrent(8) + /// .chunk(256) /// .await? /// .into_bytes_sink(); /// let bs = "Hello, World!".as_bytes(); diff --git a/core/tests/behavior/async_delete.rs b/core/tests/behavior/async_delete.rs index 0df1c0acaab..90bf6d09810 100644 --- a/core/tests/behavior/async_delete.rs +++ b/core/tests/behavior/async_delete.rs @@ -16,7 +16,8 @@ // under the License. use anyhow::Result; -use futures::{StreamExt, TryStreamExt}; +use futures::StreamExt; +use futures::TryStreamExt; use log::warn; use crate::*; diff --git a/integrations/object_store/src/send_wrapper.rs b/integrations/object_store/src/send_wrapper.rs index 34eb52690ef..82b4e89854c 100644 --- a/integrations/object_store/src/send_wrapper.rs +++ b/integrations/object_store/src/send_wrapper.rs @@ -19,20 +19,19 @@ //! Only take effect when the `send_wrapper` feature is enabled. use futures::Stream; -#[cfg(feature = "send_wrapper")] -pub use send_wrapper::SendWrapper; - #[cfg(not(feature = "send_wrapper"))] pub use noop_wrapper::NoopWrapper as SendWrapper; +#[cfg(feature = "send_wrapper")] +pub use send_wrapper::SendWrapper; #[cfg(not(feature = "send_wrapper"))] mod noop_wrapper { - use std::{ - pin::Pin, - task::{Context, Poll}, - }; + use std::pin::Pin; + use std::task::Context; + use std::task::Poll; - use futures::{Future, Stream}; + use futures::Future; + use futures::Stream; use pin_project::pin_project; #[pin_project] From 8839af40b3a19e0176d962b836125bd28de2b4a1 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 5 Jun 2024 22:31:30 +0800 Subject: [PATCH 3/3] Update core/src/docs/rfcs/3017_remove_write_copy_from.md Co-authored-by: Suyan --- core/src/docs/rfcs/3017_remove_write_copy_from.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/docs/rfcs/3017_remove_write_copy_from.md b/core/src/docs/rfcs/3017_remove_write_copy_from.md index b5344071b03..e1b0c109a95 100644 --- a/core/src/docs/rfcs/3017_remove_write_copy_from.md +++ b/core/src/docs/rfcs/3017_remove_write_copy_from.md @@ -12,7 +12,6 @@ Remove the `oio::Write::copy_from()` API pending a more thoughtful design. In [RFC-2083: Writer Sink API](./2083_writer_sink_api.md), we launched an API, initially named `sink` and changed to `copy_from`, that enables data writing from a `Reader` to a `Writer` object. The current API signature is: -s ```rust pub trait Write: Unpin + Send + Sync { /// Copies data from the given reader to the writer.