diff --git a/bin/oay/src/bin/oay.rs b/bin/oay/src/bin/oay.rs index 40151c95cd8..594622f7420 100644 --- a/bin/oay/src/bin/oay.rs +++ b/bin/oay/src/bin/oay.rs @@ -69,8 +69,7 @@ async fn webdav() -> Result<()> { }, }; - let mut builder = Fs::default(); - builder.root("/tmp"); + let builder = Fs::default().root("/tmp"); let op = Operator::new(builder)?.finish(); diff --git a/bin/oay/src/bin/webdav.rs b/bin/oay/src/bin/webdav.rs index acaf9161b5e..8c1dfe4e326 100644 --- a/bin/oay/src/bin/webdav.rs +++ b/bin/oay/src/bin/webdav.rs @@ -47,8 +47,7 @@ async fn main() -> Result<()> { }, }; - let mut builder = Fs::default(); - builder.root("/tmp"); + let builder = Fs::default().root("/tmp"); let op = Operator::new(builder)?.finish(); diff --git a/bin/oli/src/config/mod.rs b/bin/oli/src/config/mod.rs index f94a0adc66d..93d888e4ff7 100644 --- a/bin/oli/src/config/mod.rs +++ b/bin/oli/src/config/mod.rs @@ -134,11 +134,11 @@ impl Config { let filename = match fp_str.split_once(['/', '\\']) { Some((base, filename)) => { - fs_builder.root(if base.is_empty() { "/" } else { base }); + fs_builder = fs_builder.root(if base.is_empty() { "/" } else { base }); filename } _ => { - fs_builder.root("."); + fs_builder = fs_builder.root("."); s } }; diff --git a/bindings/c/include/opendal.h b/bindings/c/include/opendal.h index 899babef772..585d0be0231 100644 --- a/bindings/c/include/opendal.h +++ b/bindings/c/include/opendal.h @@ -111,11 +111,7 @@ typedef struct BlockingLister BlockingLister; * * fn main() -> Result<()> { * // Create fs backend builder. - * let mut builder = Fs::default(); - * // Set the root for fs, all operations will happen under this root. - * // - * // NOTE: the root must be absolute path. - * builder.root("/tmp"); + * let builder = Fs::default().root("/tmp"); * * // Build an `BlockingOperator` to start operating the storage. * let _: BlockingOperator = Operator::new(builder)?.finish().blocking(); @@ -136,9 +132,7 @@ typedef struct BlockingLister BlockingLister; * * async fn test() -> Result<()> { * // Create fs backend builder. - * let mut builder = S3::default(); - * builder.bucket("test"); - * builder.region("us-east-1"); + * let mut builder = S3::default().bucket("test").region("us-east-1"); * * // Build an `BlockingOperator` with blocking layer to start operating the storage. * let _: BlockingOperator = Operator::new(builder)? diff --git a/core/benches/vs_fs/src/main.rs b/core/benches/vs_fs/src/main.rs index 7ec09fb02eb..7db0b2497e3 100644 --- a/core/benches/vs_fs/src/main.rs +++ b/core/benches/vs_fs/src/main.rs @@ -28,8 +28,7 @@ fn main() { } fn bench_vs_fs(c: &mut Criterion) { - let mut cfg = services::Fs::default(); - cfg.root("/tmp/opendal/"); + let cfg = services::Fs::default().root("/tmp/opendal/"); let op = Operator::new(cfg).unwrap().finish().blocking(); let mut group = c.benchmark_group("read"); diff --git a/core/benches/vs_s3/src/main.rs b/core/benches/vs_s3/src/main.rs index e3205fc0f76..91b1be90495 100644 --- a/core/benches/vs_s3/src/main.rs +++ b/core/benches/vs_s3/src/main.rs @@ -42,12 +42,12 @@ fn main() { let region = env::var("OPENDAL_S3_REGION").unwrap(); // Init OpenDAL Operator. - let mut cfg = services::S3::default(); - cfg.endpoint(&endpoint); - cfg.access_key_id(&access_key); - cfg.secret_access_key(&secret_key); - cfg.bucket(&bucket); - cfg.region(®ion); + let cfg = services::S3::default() + .endpoint(&endpoint) + .access_key_id(&access_key) + .secret_access_key(&secret_key) + .bucket(&bucket) + .region(®ion); let op = Operator::new(cfg).unwrap().finish(); // Init AWS S3 SDK. diff --git a/core/edge/file_write_on_full_disk/src/main.rs b/core/edge/file_write_on_full_disk/src/main.rs index f232ac5ff80..a35f918e73a 100644 --- a/core/edge/file_write_on_full_disk/src/main.rs +++ b/core/edge/file_write_on_full_disk/src/main.rs @@ -24,8 +24,8 @@ use rand::prelude::*; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Fs::default(); - builder.root(&env::var("OPENDAL_FS_ROOT").expect("root must be set for this test")); + let builder = + Fs::default().root(&env::var("OPENDAL_FS_ROOT").expect("root must be set for this test")); let op = Operator::new(builder)?.finish(); let size = thread_rng().gen_range(512 * 1024 + 1..4 * 1024 * 1024); diff --git a/core/edge/s3_read_on_wasm/src/lib.rs b/core/edge/s3_read_on_wasm/src/lib.rs index 439342f7369..d0cb25c79cb 100644 --- a/core/edge/s3_read_on_wasm/src/lib.rs +++ b/core/edge/s3_read_on_wasm/src/lib.rs @@ -21,12 +21,12 @@ use wasm_bindgen::prelude::*; #[wasm_bindgen] pub async fn hello_world() -> String { - let mut cfg = S3::default(); - cfg.endpoint("http://127.0.0.1:9000"); - cfg.access_key_id("minioadmin"); - cfg.secret_access_key("minioadmin"); - cfg.bucket("test"); - cfg.region("us-east-1"); + let cfg = S3::default() + .endpoint("http://127.0.0.1:9000") + .access_key_id("minioadmin") + .secret_access_key("minioadmin") + .bucket("test") + .region("us-east-1"); let op = Operator::new(cfg).unwrap().finish(); op.write( diff --git a/core/src/layers/blocking.rs b/core/src/layers/blocking.rs index d3c04174e1a..902adff5695 100644 --- a/core/src/layers/blocking.rs +++ b/core/src/layers/blocking.rs @@ -44,9 +44,7 @@ use crate::*; /// #[tokio::main] /// async fn main() -> Result<()> { /// // Create fs backend builder. -/// let mut builder = S3::default(); -/// builder.bucket("test"); -/// builder.region("us-east-1"); +/// let mut builder = S3::default().bucket("test").region("us-east-1"); /// /// // Build an `BlockingOperator` with blocking layer to start operating the storage. /// let _: BlockingOperator = Operator::new(builder)? @@ -79,9 +77,7 @@ use crate::*; /// /// fn blocking_fn() -> Result { /// // Create fs backend builder. -/// let mut builder = S3::default(); -/// builder.bucket("test"); -/// builder.region("us-east-1"); +/// let mut builder = S3::default().bucket("test").region("us-east-1"); /// /// let handle = tokio::runtime::Handle::try_current().unwrap(); /// let _guard = handle.enter(); @@ -119,9 +115,7 @@ use crate::*; /// /// fn main() -> Result<()> { /// // Create fs backend builder. -/// let mut builder = S3::default(); -/// builder.bucket("test"); -/// builder.region("us-east-1"); +/// let mut builder = S3::default().bucket("test").region("us-east-1"); /// /// // Fetch the `EnterGuard` from global runtime. /// let _guard = RUNTIME.enter(); diff --git a/core/src/lib.rs b/core/src/lib.rs index 4e9b5f21d38..dbcde72e67f 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -47,8 +47,7 @@ //! //! fn main() -> Result<()> { //! // Pick a builder and configure it. -//! let mut builder = services::S3::default(); -//! builder.bucket("test"); +//! let mut builder = services::S3::default().bucket("test"); //! //! // Init an operator //! let op = Operator::new(builder)?.finish(); @@ -73,8 +72,7 @@ //! #[tokio::main] //! async fn main() -> Result<()> { //! // Pick a builder and configure it. -//! let mut builder = services::S3::default(); -//! builder.bucket("test"); +//! let mut builder = services::S3::default().bucket("test"); //! //! // Init an operator //! let op = Operator::new(builder)? @@ -107,8 +105,7 @@ //! #[tokio::main] //! async fn main() -> Result<()> { //! // Pick a builder and configure it. -//! let mut builder = services::S3::default(); -//! builder.bucket("test"); +//! let mut builder = services::S3::default().bucket("test"); //! //! // Init an operator //! let op = Operator::new(builder)? diff --git a/core/src/services/aliyun_drive/backend.rs b/core/src/services/aliyun_drive/backend.rs index 0ed74d121a0..77ed6ac40be 100644 --- a/core/src/services/aliyun_drive/backend.rs +++ b/core/src/services/aliyun_drive/backend.rs @@ -118,7 +118,7 @@ impl AliyunDriveBuilder { /// Set the root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -129,35 +129,35 @@ impl AliyunDriveBuilder { } /// Set access_token of this backend. - pub fn access_token(&mut self, access_token: &str) -> &mut Self { + pub fn access_token(mut self, access_token: &str) -> Self { self.config.access_token = Some(access_token.to_string()); self } /// Set client_id of this backend. - pub fn client_id(&mut self, client_id: &str) -> &mut Self { + pub fn client_id(mut self, client_id: &str) -> Self { self.config.client_id = Some(client_id.to_string()); self } /// Set client_secret of this backend. - pub fn client_secret(&mut self, client_secret: &str) -> &mut Self { + pub fn client_secret(mut self, client_secret: &str) -> Self { self.config.client_secret = Some(client_secret.to_string()); self } /// Set refresh_token of this backend. - pub fn refresh_token(&mut self, refresh_token: &str) -> &mut Self { + pub fn refresh_token(mut self, refresh_token: &str) -> Self { self.config.refresh_token = Some(refresh_token.to_string()); self } /// Set drive_type of this backend. - pub fn drive_type(&mut self, drive_type: &str) -> &mut Self { + pub fn drive_type(mut self, drive_type: &str) -> Self { self.config.drive_type = drive_type.to_string(); self @@ -169,7 +169,7 @@ impl AliyunDriveBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/aliyun_drive/docs.md b/core/src/services/aliyun_drive/docs.md index e963fd8a111..38077b5e0a6 100644 --- a/core/src/services/aliyun_drive/docs.md +++ b/core/src/services/aliyun_drive/docs.md @@ -38,21 +38,21 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create aliyun-drive backend builder. - let mut builder = AliyunDrive::default(); - // Set the root for aliyun-drive, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/path/to/dir"); - // Set the client_id. This is required. - builder.client_id("client_id"); - // Set the client_secret. This is required. - builder.client_secret("client_secret"); - // Set the refresh_token. This is required. - builder.refresh_token("refresh_token"); - // Set the drive_type. This is required. - // - // Fallback to the default type if no other types found. - builder.drive_type("resource"); + let mut builder = AliyunDrive::default() + // Set the root for aliyun-drive, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/path/to/dir") + // Set the client_id. This is required. + .client_id("client_id") + // Set the client_secret. This is required. + .client_secret("client_secret") + // Set the refresh_token. This is required. + .refresh_token("refresh_token") + // Set the drive_type. This is required. + // + // Fallback to the default type if no other types found. + .drive_type("resource"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/alluxio/backend.rs b/core/src/services/alluxio/backend.rs index ea7ab78015d..6d9aec73a1a 100644 --- a/core/src/services/alluxio/backend.rs +++ b/core/src/services/alluxio/backend.rs @@ -91,7 +91,7 @@ impl AlluxioBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -104,7 +104,7 @@ impl AlluxioBuilder { /// endpoint of this backend. /// /// Endpoint must be full uri, mostly like `http://127.0.0.1:39999`. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:39999/` self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()) @@ -119,7 +119,7 @@ impl AlluxioBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } @@ -270,10 +270,10 @@ mod test { #[test] fn test_builder_build() { - let mut builder = AlluxioBuilder::default(); - builder.root("/root").endpoint("http://127.0.0.1:39999"); - - let builder = builder.build(); + let builder = AlluxioBuilder::default() + .root("/root") + .endpoint("http://127.0.0.1:39999") + .build(); assert!(builder.is_ok()); } diff --git a/core/src/services/alluxio/docs.md b/core/src/services/alluxio/docs.md index 2c45680c6d5..05b03359fdb 100644 --- a/core/src/services/alluxio/docs.md +++ b/core/src/services/alluxio/docs.md @@ -32,12 +32,11 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Alluxio::default(); - - // set the storage bucket for OpenDAL - builder.root("/"); - // set the endpoint for OpenDAL - builder.endpoint("http://127.0.0.1:39999"); + let mut builder = Alluxio::default() + // set the storage bucket for OpenDAL + .root("/") + // set the endpoint for OpenDAL + .endpoint("http://127.0.0.1:39999"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/atomicserver/backend.rs b/core/src/services/atomicserver/backend.rs index d9d4dc1305a..5812b41d38f 100644 --- a/core/src/services/atomicserver/backend.rs +++ b/core/src/services/atomicserver/backend.rs @@ -84,19 +84,19 @@ impl Debug for AtomicserverBuilder { impl AtomicserverBuilder { /// Set the root for Atomicserver. - pub fn root(&mut self, path: &str) -> &mut Self { + pub fn root(mut self, path: &str) -> Self { self.config.root = Some(path.into()); self } /// Set the server address for Atomicserver. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = Some(endpoint.into()); self } /// Set the private key for agent used for Atomicserver. - pub fn private_key(&mut self, private_key: &str) -> &mut Self { + pub fn private_key(mut self, private_key: &str) -> Self { self.config.private_key = Some(private_key.into()); self } @@ -105,13 +105,13 @@ impl AtomicserverBuilder { /// For example, if the subject URL for the agent being used /// is ${endpoint}/agents/lTB+W3C/2YfDu9IAVleEy34uCmb56iXXuzWCKBVwdRI= /// Then the required public key is `lTB+W3C/2YfDu9IAVleEy34uCmb56iXXuzWCKBVwdRI=` - pub fn public_key(&mut self, public_key: &str) -> &mut Self { + pub fn public_key(mut self, public_key: &str) -> Self { self.config.public_key = Some(public_key.into()); self } /// Set the parent resource id (url) that Atomicserver uses to store resources under. - pub fn parent_resource_id(&mut self, parent_resource_id: &str) -> &mut Self { + pub fn parent_resource_id(mut self, parent_resource_id: &str) -> Self { self.config.parent_resource_id = Some(parent_resource_id.into()); self } diff --git a/core/src/services/atomicserver/docs.md b/core/src/services/atomicserver/docs.md index 121c71b2d9d..c22260f4bc9 100644 --- a/core/src/services/atomicserver/docs.md +++ b/core/src/services/atomicserver/docs.md @@ -35,16 +35,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Atomicserver::default(); - - // Set the server address for Atomicserver - builder.endpoint("http://localhost:9883"); - // Set the public/private key for agent for Atomicserver - builder.private_key(""); - builder.public_key(""); - // Set the parent resource id for Atomicserver. In this case - // We are using the root resource (Drive) - builder.parent_resource_id("http://localhost:9883"); + let mut builder = Atomicserver::default() + // Set the server address for Atomicserver + .endpoint("http://localhost:9883") + // Set the public/private key for agent for Atomicserver + .private_key("") + .public_key("") + // Set the parent resource id for Atomicserver. In this case + // We are using the root resource (Drive) + .parent_resource_id("http://localhost:9883"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/azblob/backend.rs b/core/src/services/azblob/backend.rs index ba828a16546..3c907d397f2 100644 --- a/core/src/services/azblob/backend.rs +++ b/core/src/services/azblob/backend.rs @@ -148,7 +148,7 @@ impl AzblobBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -157,7 +157,7 @@ impl AzblobBuilder { } /// Set container name of this backend. - pub fn container(&mut self, container: &str) -> &mut Self { + pub fn container(mut self, container: &str) -> Self { self.config.container = container.to_string(); self @@ -169,7 +169,7 @@ impl AzblobBuilder { /// /// - Azblob: `https://accountname.blob.core.windows.net` /// - Azurite: `http://127.0.0.1:10000/devstoreaccount1` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()); @@ -182,7 +182,7 @@ impl AzblobBuilder { /// /// - If account_name is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn account_name(&mut self, account_name: &str) -> &mut Self { + pub fn account_name(mut self, account_name: &str) -> Self { if !account_name.is_empty() { self.config.account_name = Some(account_name.to_string()); } @@ -194,7 +194,7 @@ impl AzblobBuilder { /// /// - If account_key is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn account_key(&mut self, account_key: &str) -> &mut Self { + pub fn account_key(mut self, account_key: &str) -> Self { if !account_key.is_empty() { self.config.account_key = Some(account_key.to_string()); } @@ -214,7 +214,7 @@ impl AzblobBuilder { /// /// SSE related options should be set carefully to make them works. /// Please use `server_side_encryption_with_*` helpers if even possible. - pub fn encryption_key(&mut self, v: &str) -> &mut Self { + pub fn encryption_key(mut self, v: &str) -> Self { if !v.is_empty() { self.config.encryption_key = Some(v.to_string()); } @@ -234,7 +234,7 @@ impl AzblobBuilder { /// /// SSE related options should be set carefully to make them works. /// Please use `server_side_encryption_with_*` helpers if even possible. - pub fn encryption_key_sha256(&mut self, v: &str) -> &mut Self { + pub fn encryption_key_sha256(mut self, v: &str) -> Self { if !v.is_empty() { self.config.encryption_key_sha256 = Some(v.to_string()); } @@ -254,7 +254,7 @@ impl AzblobBuilder { /// /// SSE related options should be set carefully to make them works. /// Please use `server_side_encryption_with_*` helpers if even possible. - pub fn encryption_algorithm(&mut self, v: &str) -> &mut Self { + pub fn encryption_algorithm(mut self, v: &str) -> Self { if !v.is_empty() { self.config.encryption_algorithm = Some(v.to_string()); } @@ -275,7 +275,7 @@ impl AzblobBuilder { /// Function that helps the user to set the server-side customer-provided encryption key, the key's SHA256, and the algorithm. /// See [Server-side encryption with customer-provided keys (CPK)](https://learn.microsoft.com/en-us/azure/storage/blobs/encryption-customer-provided-keys) /// for more info. - pub fn server_side_encryption_with_customer_key(&mut self, key: &[u8]) -> &mut Self { + pub fn server_side_encryption_with_customer_key(mut self, key: &[u8]) -> Self { // Only AES256 is supported for now self.config.encryption_algorithm = Some("AES256".to_string()); self.config.encryption_key = Some(BASE64_STANDARD.encode(key)); @@ -291,7 +291,7 @@ impl AzblobBuilder { /// /// See [Grant limited access to Azure Storage resources using shared access signatures (SAS)](https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview) /// for more info. - pub fn sas_token(&mut self, sas_token: &str) -> &mut Self { + pub fn sas_token(mut self, sas_token: &str) -> Self { if !sas_token.is_empty() { self.config.sas_token = Some(sas_token.to_string()); } @@ -305,13 +305,13 @@ impl AzblobBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } /// Set maximum batch operations of this backend. - pub fn batch_max_operations(&mut self, batch_max_operations: usize) -> &mut Self { + pub fn batch_max_operations(mut self, batch_max_operations: usize) -> Self { self.config.batch_max_operations = Some(batch_max_operations); self @@ -360,7 +360,7 @@ impl AzblobBuilder { let mut builder = AzblobBuilder::default(); if let Some(sas_token) = conn_map.get("SharedAccessSignature") { - builder.sas_token(sas_token); + builder = builder.sas_token(sas_token); } else { let account_name = conn_map.get("AccountName").ok_or_else(|| { Error::new( @@ -369,7 +369,7 @@ impl AzblobBuilder { ) .with_operation("Builder::from_connection_string") })?; - builder.account_name(account_name); + builder = builder.account_name(account_name); let account_key = conn_map.get("AccountKey").ok_or_else(|| { Error::new( ErrorKind::ConfigInvalid, @@ -377,11 +377,11 @@ impl AzblobBuilder { ) .with_operation("Builder::from_connection_string") })?; - builder.account_key(account_key); + builder = builder.account_key(account_key); } if let Some(v) = conn_map.get("BlobEndpoint") { - builder.endpoint(v); + builder = builder.endpoint(v); } else if let Some(v) = conn_map.get("EndpointSuffix") { let protocol = conn_map.get("DefaultEndpointsProtocol").unwrap_or(&"https"); let account_name = builder @@ -396,7 +396,7 @@ impl AzblobBuilder { .with_operation("Builder::from_connection_string") })? .clone(); - builder.endpoint(&format!("{protocol}://{account_name}.blob.{v}")); + builder = builder.endpoint(&format!("{protocol}://{account_name}.blob.{v}")); } Ok(builder) diff --git a/core/src/services/azblob/docs.md b/core/src/services/azblob/docs.md index 961def0a574..6f732a2391c 100644 --- a/core/src/services/azblob/docs.md +++ b/core/src/services/azblob/docs.md @@ -49,26 +49,26 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create azblob backend builder. - let mut builder = Azblob::default(); - // Set the root for azblob, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/path/to/dir"); - // Set the container name, this is required. - builder.container("test"); - // Set the endpoint, this is required. - // - // For examples: - // - "http://127.0.0.1:10000/devstoreaccount1" - // - "https://accountname.blob.core.windows.net" - builder.endpoint("http://127.0.0.1:10000/devstoreaccount1"); - // Set the account_name and account_key. - // - // OpenDAL will try load credential from the env. - // If credential not set and no valid credential in env, OpenDAL will - // send request without signing like anonymous user. - builder.account_name("devstoreaccount1"); - builder.account_key("Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="); + let mut builder = Azblob::default() + // Set the root for azblob, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/path/to/dir") + // Set the container name, this is required. + .container("test") + // Set the endpoint, this is required. + // + // For examples: + // - "http://127.0.0.1:10000/devstoreaccount1" + // - "https://accountname.blob.core.windows.net" + .endpoint("http://127.0.0.1:10000/devstoreaccount1") + // Set the account_name and account_key. + // + // OpenDAL will try load credential from the env. + // If credential not set and no valid credential in env, OpenDAL will + // send request without signing like anonymous user. + .account_name("devstoreaccount1") + .account_key("Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="); // `Accessor` provides the low level APIs, we will use `Operator` normally. let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/azdls/backend.rs b/core/src/services/azdls/backend.rs index d8ad4c5708b..b4489b557e0 100644 --- a/core/src/services/azdls/backend.rs +++ b/core/src/services/azdls/backend.rs @@ -111,7 +111,7 @@ impl AzdlsBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -120,7 +120,7 @@ impl AzdlsBuilder { } /// Set filesystem name of this backend. - pub fn filesystem(&mut self, filesystem: &str) -> &mut Self { + pub fn filesystem(mut self, filesystem: &str) -> Self { self.config.filesystem = filesystem.to_string(); self @@ -132,7 +132,7 @@ impl AzdlsBuilder { /// /// - Azblob: `https://accountname.blob.core.windows.net` /// - Azurite: `http://127.0.0.1:10000/devstoreaccount1` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()); @@ -145,7 +145,7 @@ impl AzdlsBuilder { /// /// - If account_name is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn account_name(&mut self, account_name: &str) -> &mut Self { + pub fn account_name(mut self, account_name: &str) -> Self { if !account_name.is_empty() { self.config.account_name = Some(account_name.to_string()); } @@ -157,7 +157,7 @@ impl AzdlsBuilder { /// /// - If account_key is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn account_key(&mut self, account_key: &str) -> &mut Self { + pub fn account_key(mut self, account_key: &str) -> Self { if !account_key.is_empty() { self.config.account_key = Some(account_key.to_string()); } @@ -171,7 +171,7 @@ impl AzdlsBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/azdls/docs.md b/core/src/services/azdls/docs.md index 8ac57b5a05c..73d9a1d13e9 100644 --- a/core/src/services/azdls/docs.md +++ b/core/src/services/azdls/docs.md @@ -45,25 +45,25 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create azdls backend builder. - let mut builder = Azdls::default(); - // Set the root for azdls, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/path/to/dir"); - // Set the filesystem name, this is required. - builder.filesystem("test"); - // Set the endpoint, this is required. - // - // For examples: - // - "https://accountname.dfs.core.windows.net" - builder.endpoint("https://accountname.dfs.core.windows.net"); - // Set the account_name and account_key. - // - // OpenDAL will try load credential from the env. - // If credential not set and no valid credential in env, OpenDAL will - // send request without signing like anonymous user. - builder.account_name("account_name"); - builder.account_key("account_key"); + let mut builder = Azdls::default() + // Set the root for azdls, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/path/to/dir") + // Set the filesystem name, this is required. + .filesystem("test") + // Set the endpoint, this is required. + // + // For examples: + // - "https://accountname.dfs.core.windows.net" + .endpoint("https://accountname.dfs.core.windows.net") + // Set the account_name and account_key. + // + // OpenDAL will try load credential from the env. + // If credential not set and no valid credential in env, OpenDAL will + // send request without signing like anonymous user. + .account_name("account_name") + .account_key("account_key"); // `Accessor` provides the low level APIs, we will use `Operator` normally. let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/azfile/backend.rs b/core/src/services/azfile/backend.rs index d722b37989b..4fe74c9fcb1 100644 --- a/core/src/services/azfile/backend.rs +++ b/core/src/services/azfile/backend.rs @@ -109,7 +109,7 @@ impl AzfileBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -118,7 +118,7 @@ impl AzfileBuilder { } /// Set endpoint of this backend. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()); @@ -131,7 +131,7 @@ impl AzfileBuilder { /// /// - If account_name is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn account_name(&mut self, account_name: &str) -> &mut Self { + pub fn account_name(mut self, account_name: &str) -> Self { if !account_name.is_empty() { self.config.account_name = Some(account_name.to_string()); } @@ -143,7 +143,7 @@ impl AzfileBuilder { /// /// - If account_key is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn account_key(&mut self, account_key: &str) -> &mut Self { + pub fn account_key(mut self, account_key: &str) -> Self { if !account_key.is_empty() { self.config.account_key = Some(account_key.to_string()); } @@ -155,7 +155,7 @@ impl AzfileBuilder { /// /// # Notes /// You can find more about from: - pub fn share_name(&mut self, share_name: &str) -> &mut Self { + pub fn share_name(mut self, share_name: &str) -> Self { if !share_name.is_empty() { self.config.share_name = share_name.to_string(); } @@ -169,7 +169,7 @@ impl AzfileBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/azfile/docs.md b/core/src/services/azfile/docs.md index 487a9724a7b..962b2830ad2 100644 --- a/core/src/services/azfile/docs.md +++ b/core/src/services/azfile/docs.md @@ -37,25 +37,25 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create azfile backend builder. - let mut builder = Azfile::default(); - // Set the root for azfile, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/path/to/dir"); - // Set the filesystem name, this is required. - builder.share_name("test"); - // Set the endpoint, this is required. - // - // For examples: - // - "https://accountname.file.core.windows.net" - builder.endpoint("https://accountname.file.core.windows.net"); - // Set the account_name and account_key. - // - // OpenDAL will try load credential from the env. - // If credential not set and no valid credential in env, OpenDAL will - // send request without signing like anonymous user. - builder.account_name("account_name"); - builder.account_key("account_key"); + let mut builder = Azfile::default() + // Set the root for azfile, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/path/to/dir") + // Set the filesystem name, this is required. + .share_name("test") + // Set the endpoint, this is required. + // + // For examples: + // - "https://accountname.file.core.windows.net" + .endpoint("https://accountname.file.core.windows.net") + // Set the account_name and account_key. + // + // OpenDAL will try load credential from the env. + // If credential not set and no valid credential in env, OpenDAL will + // send request without signing like anonymous user. + .account_name("account_name") + .account_key("account_key"); // `Accessor` provides the low level APIs, we will use `Operator` normally. let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/b2/backend.rs b/core/src/services/b2/backend.rs index 0c6968e4e24..2a7de8922fc 100644 --- a/core/src/services/b2/backend.rs +++ b/core/src/services/b2/backend.rs @@ -113,7 +113,7 @@ impl B2Builder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -124,7 +124,7 @@ impl B2Builder { } /// application_key_id of this backend. - pub fn application_key_id(&mut self, application_key_id: &str) -> &mut Self { + pub fn application_key_id(mut self, application_key_id: &str) -> Self { self.config.application_key_id = if application_key_id.is_empty() { None } else { @@ -135,7 +135,7 @@ impl B2Builder { } /// application_key of this backend. - pub fn application_key(&mut self, application_key: &str) -> &mut Self { + pub fn application_key(mut self, application_key: &str) -> Self { self.config.application_key = if application_key.is_empty() { None } else { @@ -147,7 +147,7 @@ impl B2Builder { /// Set bucket name of this backend. /// You can find it in - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { self.config.bucket = bucket.to_string(); self @@ -155,7 +155,7 @@ impl B2Builder { /// Set bucket id of this backend. /// You can find it in - pub fn bucket_id(&mut self, bucket_id: &str) -> &mut Self { + pub fn bucket_id(mut self, bucket_id: &str) -> Self { self.config.bucket_id = bucket_id.to_string(); self @@ -167,7 +167,7 @@ impl B2Builder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/b2/docs.md b/core/src/services/b2/docs.md index 01b94758c48..d4d30710eda 100644 --- a/core/src/services/b2/docs.md +++ b/core/src/services/b2/docs.md @@ -35,18 +35,17 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = B2::default(); - - // set the storage bucket for OpenDAL - builder.root("/"); - // set the key_id for OpenDAL - builder.application_key_id("xxxxxxxxxx"); - // set the key_id for OpenDAL - builder.application_key("xxxxxxxxxx"); - // set the bucket name for OpenDAL - builder.bucket("opendal"); - // set the bucket_id for OpenDAL - builder.bucket_id("xxxxxxxxxxxxx"); + let mut builder = B2::default() + // set the storage bucket for OpenDAL + .root("/") + // set the key_id for OpenDAL + .application_key_id("xxxxxxxxxx") + // set the key_id for OpenDAL + .application_key("xxxxxxxxxx") + // set the bucket name for OpenDAL + .bucket("opendal") + // set the bucket_id for OpenDAL + .bucket_id("xxxxxxxxxxxxx"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/cacache/backend.rs b/core/src/services/cacache/backend.rs index 14262d1392a..28da45c469c 100644 --- a/core/src/services/cacache/backend.rs +++ b/core/src/services/cacache/backend.rs @@ -53,7 +53,7 @@ pub struct CacacheBuilder { impl CacacheBuilder { /// Set the path to the cacache data directory. Will create if not exists. - pub fn datadir(&mut self, path: &str) -> &mut Self { + pub fn datadir(mut self, path: &str) -> Self { self.config.datadir = Some(path.into()); self } diff --git a/core/src/services/cacache/docs.md b/core/src/services/cacache/docs.md index eba540a5bb1..01ebc082174 100644 --- a/core/src/services/cacache/docs.md +++ b/core/src/services/cacache/docs.md @@ -30,8 +30,7 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Cacache::default(); - builder.datadir("/tmp/opendal/cacache"); + let mut builder = Cacache::default().datadir("/tmp/opendal/cacache"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/chainsafe/backend.rs b/core/src/services/chainsafe/backend.rs index 9a88a2257b4..2431d0e2610 100644 --- a/core/src/services/chainsafe/backend.rs +++ b/core/src/services/chainsafe/backend.rs @@ -95,7 +95,7 @@ impl ChainsafeBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -108,7 +108,7 @@ impl ChainsafeBuilder { /// api_key of this backend. /// /// required. - pub fn api_key(&mut self, api_key: &str) -> &mut Self { + pub fn api_key(mut self, api_key: &str) -> Self { self.config.api_key = if api_key.is_empty() { None } else { @@ -119,7 +119,7 @@ impl ChainsafeBuilder { } /// Set bucket_id name of this backend. - pub fn bucket_id(&mut self, bucket_id: &str) -> &mut Self { + pub fn bucket_id(mut self, bucket_id: &str) -> Self { self.config.bucket_id = bucket_id.to_string(); self @@ -131,7 +131,7 @@ impl ChainsafeBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/chainsafe/docs.md b/core/src/services/chainsafe/docs.md index a1956acf40b..64d9b3ee8e7 100644 --- a/core/src/services/chainsafe/docs.md +++ b/core/src/services/chainsafe/docs.md @@ -33,14 +33,13 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Chainsafe::default(); - - // set the storage root for OpenDAL - builder.root("/"); - // set the bucket_id for OpenDAL - builder.bucket_id("opendal"); - // set the api_key for OpenDAL - builder.api_key("xxxxxxxxxxxxx"); + let mut builder = Chainsafe::default() + // set the storage root for OpenDAL + .root("/") + // set the bucket_id for OpenDAL + .bucket_id("opendal") + // set the api_key for OpenDAL + .api_key("xxxxxxxxxxxxx"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/cloudflare_kv/backend.rs b/core/src/services/cloudflare_kv/backend.rs index e259debbb58..0ce628e5077 100644 --- a/core/src/services/cloudflare_kv/backend.rs +++ b/core/src/services/cloudflare_kv/backend.rs @@ -89,7 +89,7 @@ impl Debug for CloudflareKvBuilder { impl CloudflareKvBuilder { /// Set the token used to authenticate with CloudFlare. - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { self.config.token = Some(token.to_string()) } @@ -97,7 +97,7 @@ impl CloudflareKvBuilder { } /// Set the account ID used to authenticate with CloudFlare. - pub fn account_id(&mut self, account_id: &str) -> &mut Self { + pub fn account_id(mut self, account_id: &str) -> Self { if !account_id.is_empty() { self.config.account_id = Some(account_id.to_string()) } @@ -105,7 +105,7 @@ impl CloudflareKvBuilder { } /// Set the namespace ID. - pub fn namespace_id(&mut self, namespace_id: &str) -> &mut Self { + pub fn namespace_id(mut self, namespace_id: &str) -> Self { if !namespace_id.is_empty() { self.config.namespace_id = Some(namespace_id.to_string()) } @@ -113,7 +113,7 @@ impl CloudflareKvBuilder { } /// Set the root within this backend. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } diff --git a/core/src/services/compfs/backend.rs b/core/src/services/compfs/backend.rs index 6350a1b6bd8..d2fa7f5d205 100644 --- a/core/src/services/compfs/backend.rs +++ b/core/src/services/compfs/backend.rs @@ -53,7 +53,7 @@ pub struct CompfsBuilder { impl CompfsBuilder { /// Set root for Compfs - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { diff --git a/core/src/services/cos/backend.rs b/core/src/services/cos/backend.rs index 483ea4f2440..d94201490e4 100644 --- a/core/src/services/cos/backend.rs +++ b/core/src/services/cos/backend.rs @@ -95,7 +95,7 @@ impl CosBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -110,7 +110,7 @@ impl CosBuilder { /// # Examples /// /// - `https://cos.ap-singapore.myqcloud.com` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()); } @@ -121,7 +121,7 @@ impl CosBuilder { /// Set secret_id of this backend. /// - If it is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn secret_id(&mut self, secret_id: &str) -> &mut Self { + pub fn secret_id(mut self, secret_id: &str) -> Self { if !secret_id.is_empty() { self.config.secret_id = Some(secret_id.to_string()); } @@ -132,7 +132,7 @@ impl CosBuilder { /// Set secret_key of this backend. /// - If it is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn secret_key(&mut self, secret_key: &str) -> &mut Self { + pub fn secret_key(mut self, secret_key: &str) -> Self { if !secret_key.is_empty() { self.config.secret_key = Some(secret_key.to_string()); } @@ -142,7 +142,7 @@ impl CosBuilder { /// Set bucket of this backend. /// The param is required. - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { if !bucket.is_empty() { self.config.bucket = Some(bucket.to_string()); } @@ -156,7 +156,7 @@ impl CosBuilder { /// For examples: /// /// - envs like `TENCENTCLOUD_SECRET_ID` - pub fn disable_config_load(&mut self) -> &mut Self { + pub fn disable_config_load(mut self) -> Self { self.config.disable_config_load = true; self } @@ -167,7 +167,7 @@ impl CosBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/cos/docs.md b/core/src/services/cos/docs.md index 83d83df4765..f808a456619 100644 --- a/core/src/services/cos/docs.md +++ b/core/src/services/cos/docs.md @@ -35,19 +35,18 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Cos::default(); - - // set the storage bucket for OpenDAL - builder.bucket("test"); - // set the endpoint for OpenDAL - builder.endpoint("https://cos.ap-singapore.myqcloud.com"); - // Set the access_key_id and secret_access_key. - // - // OpenDAL will try load credential from the env. - // If credential not set and no valid credential in env, OpenDAL will - // send request without signing like anonymous user. - builder.secret_id("secret_id"); - builder.secret_key("secret_access_key"); + let mut builder = Cos::default() + // set the storage bucket for OpenDAL + .bucket("test") + // set the endpoint for OpenDAL + .endpoint("https://cos.ap-singapore.myqcloud.com") + // Set the access_key_id and secret_access_key. + // + // OpenDAL will try load credential from the env. + // If credential not set and no valid credential in env, OpenDAL will + // send request without signing like anonymous user. + .secret_id("secret_id") + .secret_key("secret_access_key"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/d1/backend.rs b/core/src/services/d1/backend.rs index d1344d244fb..ae0fb132ed4 100644 --- a/core/src/services/d1/backend.rs +++ b/core/src/services/d1/backend.rs @@ -95,7 +95,7 @@ impl D1Builder { /// Set api token for the cloudflare d1 service. /// /// create a api token from [here](https://dash.cloudflare.com/profile/api-tokens) - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { self.config.token = Some(token.to_string()); } @@ -106,7 +106,7 @@ impl D1Builder { /// /// get the account identifier from Workers & Pages -> Overview -> Account ID /// If not specified, it will return an error when building. - pub fn account_id(&mut self, account_id: &str) -> &mut Self { + pub fn account_id(mut self, account_id: &str) -> Self { if !account_id.is_empty() { self.config.account_id = Some(account_id.to_string()); } @@ -117,7 +117,7 @@ impl D1Builder { /// /// get the database identifier from Workers & Pages -> D1 -> [Your Database] -> Database ID /// If not specified, it will return an error when building. - pub fn database_id(&mut self, database_id: &str) -> &mut Self { + pub fn database_id(mut self, database_id: &str) -> Self { if !database_id.is_empty() { self.config.database_id = Some(database_id.to_string()); } @@ -127,7 +127,7 @@ impl D1Builder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } @@ -137,7 +137,7 @@ impl D1Builder { /// Set the table name of the d1 service to read/write. /// /// If not specified, it will return an error when building. - pub fn table(&mut self, table: &str) -> &mut Self { + pub fn table(mut self, table: &str) -> Self { if !table.is_empty() { self.config.table = Some(table.to_owned()); } @@ -147,7 +147,7 @@ impl D1Builder { /// Set the key field name of the d1 service to read/write. /// /// Default to `key` if not specified. - pub fn key_field(&mut self, key_field: &str) -> &mut Self { + pub fn key_field(mut self, key_field: &str) -> Self { if !key_field.is_empty() { self.config.key_field = Some(key_field.to_string()); } @@ -157,7 +157,7 @@ impl D1Builder { /// Set the value field name of the d1 service to read/write. /// /// Default to `value` if not specified. - pub fn value_field(&mut self, value_field: &str) -> &mut Self { + pub fn value_field(mut self, value_field: &str) -> Self { if !value_field.is_empty() { self.config.value_field = Some(value_field.to_string()); } diff --git a/core/src/services/d1/docs.md b/core/src/services/d1/docs.md index 05d693f626f..798cc834ba5 100644 --- a/core/src/services/d1/docs.md +++ b/core/src/services/d1/docs.md @@ -34,8 +34,7 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = D1::default(); - builder + let mut builder = D1::default() .token("token") .account_id("account_id") .database_id("database_id") diff --git a/core/src/services/dashmap/backend.rs b/core/src/services/dashmap/backend.rs index ffd22d797c0..8b4d8d728c3 100644 --- a/core/src/services/dashmap/backend.rs +++ b/core/src/services/dashmap/backend.rs @@ -48,7 +48,7 @@ pub struct DashmapBuilder { impl DashmapBuilder { /// Set the root for dashmap. - pub fn root(&mut self, path: &str) -> &mut Self { + pub fn root(mut self, path: &str) -> Self { self.config.root = Some(path.into()); self } diff --git a/core/src/services/dbfs/backend.rs b/core/src/services/dbfs/backend.rs index f511560fa56..4673ceb4e0c 100644 --- a/core/src/services/dbfs/backend.rs +++ b/core/src/services/dbfs/backend.rs @@ -85,7 +85,7 @@ impl DbfsBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -99,7 +99,7 @@ impl DbfsBuilder { /// /// - Azure: `https://adb-1234567890123456.78.azuredatabricks.net` /// - Aws: `https://dbc-123a5678-90bc.cloud.databricks.com` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -109,7 +109,7 @@ impl DbfsBuilder { } /// Set the token of this backend. - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { self.config.token = Some(token.to_string()); } diff --git a/core/src/services/dbfs/docs.md b/core/src/services/dbfs/docs.md index 966ed014d05..fb5958bab4e 100644 --- a/core/src/services/dbfs/docs.md +++ b/core/src/services/dbfs/docs.md @@ -36,19 +36,19 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Dbfs::default(); - // set the root for Dbfs, all operations will happen under this root - // - // Note: - // if the root is not exists, the builder will automatically create the - // root directory for you - // if the root exists and is a directory, the builder will continue working - // if the root exists and is a folder, the builder will fail on building backend - builder.root("/path/to/dir"); - // set the endpoint of Dbfs workspace - builder.endpoint("https://adb-1234567890123456.78.azuredatabricks.net"); - // set the personal access token for builder - builder.token("access_token"); + let mut builder = Dbfs::default() + // set the root for Dbfs, all operations will happen under this root + // + // Note: + // if the root is not exists, the builder will automatically create the + // root directory for you + // if the root exists and is a directory, the builder will continue working + // if the root exists and is a folder, the builder will fail on building backend + .root("/path/to/dir") + // set the endpoint of Dbfs workspace + .endpoint("https://adb-1234567890123456.78.azuredatabricks.net") + // set the personal access token for builder + .token("access_token"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/dropbox/builder.rs b/core/src/services/dropbox/builder.rs index 21383483382..29ee07a852e 100644 --- a/core/src/services/dropbox/builder.rs +++ b/core/src/services/dropbox/builder.rs @@ -86,7 +86,7 @@ impl DropboxBuilder { /// Set the root directory for dropbox. /// /// Default to `/` if not set. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = Some(root.to_string()); self } @@ -97,7 +97,7 @@ impl DropboxBuilder { /// /// NOTE: this token will be expired in 4 hours. /// If you are trying to use the Dropbox service in a long time, please set a refresh_token instead. - pub fn access_token(&mut self, access_token: &str) -> &mut Self { + pub fn access_token(mut self, access_token: &str) -> Self { self.config.access_token = Some(access_token.to_string()); self } @@ -107,7 +107,7 @@ impl DropboxBuilder { /// You can get the refresh token via OAuth 2.0 Flow of Dropbox. /// /// OpenDAL will use this refresh token to get a new access token when the old one is expired. - pub fn refresh_token(&mut self, refresh_token: &str) -> &mut Self { + pub fn refresh_token(mut self, refresh_token: &str) -> Self { self.config.refresh_token = Some(refresh_token.to_string()); self } @@ -115,7 +115,7 @@ impl DropboxBuilder { /// Set the client id for Dropbox. /// /// This is required for OAuth 2.0 Flow to refresh the access token. - pub fn client_id(&mut self, client_id: &str) -> &mut Self { + pub fn client_id(mut self, client_id: &str) -> Self { self.config.client_id = Some(client_id.to_string()); self } @@ -123,7 +123,7 @@ impl DropboxBuilder { /// Set the client secret for Dropbox. /// /// This is required for OAuth 2.0 Flow with refresh the access token. - pub fn client_secret(&mut self, client_secret: &str) -> &mut Self { + pub fn client_secret(mut self, client_secret: &str) -> Self { self.config.client_secret = Some(client_secret.to_string()); self } @@ -134,7 +134,7 @@ impl DropboxBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, http_client: HttpClient) -> &mut Self { + pub fn http_client(mut self, http_client: HttpClient) -> Self { self.http_client = Some(http_client); self } diff --git a/core/src/services/dropbox/docs.md b/core/src/services/dropbox/docs.md index 0cc51c51252..30cdaf1cf36 100644 --- a/core/src/services/dropbox/docs.md +++ b/core/src/services/dropbox/docs.md @@ -54,9 +54,9 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Dropbox::default(); - builder.root("/opendal"); - builder.access_token(""); + let mut builder = Dropbox::default() + .root("/opendal") + .access_token(""); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/etcd/backend.rs b/core/src/services/etcd/backend.rs index 05648a39ef7..90eee72566b 100644 --- a/core/src/services/etcd/backend.rs +++ b/core/src/services/etcd/backend.rs @@ -127,7 +127,7 @@ impl EtcdBuilder { /// set the network address of etcd service. /// /// default: "http://127.0.0.1:2379" - pub fn endpoints(&mut self, endpoints: &str) -> &mut Self { + pub fn endpoints(mut self, endpoints: &str) -> Self { if !endpoints.is_empty() { self.config.endpoints = Some(endpoints.to_owned()); } @@ -137,7 +137,7 @@ impl EtcdBuilder { /// set the username for etcd /// /// default: no username - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(mut self, username: &str) -> Self { if !username.is_empty() { self.config.username = Some(username.to_owned()); } @@ -147,7 +147,7 @@ impl EtcdBuilder { /// set the password for etcd /// /// default: no password - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { if !password.is_empty() { self.config.password = Some(password.to_owned()); } @@ -157,7 +157,7 @@ impl EtcdBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } @@ -167,7 +167,7 @@ impl EtcdBuilder { /// Set the certificate authority file path. /// /// default is None - pub fn ca_path(&mut self, ca_path: &str) -> &mut Self { + pub fn ca_path(mut self, ca_path: &str) -> Self { if !ca_path.is_empty() { self.config.ca_path = Some(ca_path.to_string()) } @@ -177,7 +177,7 @@ impl EtcdBuilder { /// Set the certificate file path. /// /// default is None - pub fn cert_path(&mut self, cert_path: &str) -> &mut Self { + pub fn cert_path(mut self, cert_path: &str) -> Self { if !cert_path.is_empty() { self.config.cert_path = Some(cert_path.to_string()) } @@ -187,7 +187,7 @@ impl EtcdBuilder { /// Set the key file path. /// /// default is None - pub fn key_path(&mut self, key_path: &str) -> &mut Self { + pub fn key_path(mut self, key_path: &str) -> Self { if !key_path.is_empty() { self.config.key_path = Some(key_path.to_string()) } diff --git a/core/src/services/foundationdb/backend.rs b/core/src/services/foundationdb/backend.rs index 890db5cd1b7..34fbe5f5be7 100644 --- a/core/src/services/foundationdb/backend.rs +++ b/core/src/services/foundationdb/backend.rs @@ -69,13 +69,13 @@ pub struct FoundationdbBuilder { impl FoundationdbBuilder { /// Set the root for Foundationdb. - pub fn root(&mut self, path: &str) -> &mut Self { + pub fn root(mut self, path: &str) -> Self { self.config.root = Some(path.into()); self } /// Set the config path for Foundationdb. If not set, will fallback to use default - pub fn config_path(&mut self, path: &str) -> &mut Self { + pub fn config_path(mut self, path: &str) -> Self { self.config.config_path = Some(path.into()); self } diff --git a/core/src/services/foundationdb/docs.md b/core/src/services/foundationdb/docs.md index 962dad0cb25..e4ad8a005d1 100644 --- a/core/src/services/foundationdb/docs.md +++ b/core/src/services/foundationdb/docs.md @@ -33,8 +33,8 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Foundationdb::default(); - builder.config_path("/etc/foundationdb/foundationdb.conf"); + let mut builder = Foundationdb::default() + .config_path("/etc/foundationdb/foundationdb.conf"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/fs/backend.rs b/core/src/services/fs/backend.rs index 637bc624de2..dd1ec77b9e0 100644 --- a/core/src/services/fs/backend.rs +++ b/core/src/services/fs/backend.rs @@ -60,7 +60,7 @@ pub struct FsBuilder { impl FsBuilder { /// Set root for backend. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()); } @@ -74,7 +74,7 @@ impl FsBuilder { /// /// - When append is enabled, we will not use atomic write /// to avoid data loss and performance issue. - pub fn atomic_write_dir(&mut self, dir: &str) -> &mut Self { + pub fn atomic_write_dir(mut self, dir: &str) -> Self { if !dir.is_empty() { self.config.atomic_write_dir = Some(dir.to_string()); } diff --git a/core/src/services/fs/docs.md b/core/src/services/fs/docs.md index 34a5628ad00..10dcf9c2616 100644 --- a/core/src/services/fs/docs.md +++ b/core/src/services/fs/docs.md @@ -35,11 +35,11 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create fs backend builder. - let mut builder = Fs::default(); - // Set the root for fs, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/tmp"); + let mut builder = Fs::default() + // Set the root for fs, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/tmp"); // `Accessor` provides the low level APIs, we will use `Operator` normally. let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/ftp/backend.rs b/core/src/services/ftp/backend.rs index 67209fd7888..c277cfac7bc 100644 --- a/core/src/services/ftp/backend.rs +++ b/core/src/services/ftp/backend.rs @@ -46,7 +46,7 @@ use super::writer::FtpWriter; use crate::raw::*; use crate::*; -/// Config for Ftpservices support. +/// Config for Ftp services support. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -93,7 +93,7 @@ impl Debug for FtpBuilder { impl FtpBuilder { /// set endpoint for ftp backend. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -104,7 +104,7 @@ impl FtpBuilder { } /// set root path for ftp backend. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -115,7 +115,7 @@ impl FtpBuilder { } /// set user for ftp backend. - pub fn user(&mut self, user: &str) -> &mut Self { + pub fn user(mut self, user: &str) -> Self { self.config.user = if user.is_empty() { None } else { @@ -126,7 +126,7 @@ impl FtpBuilder { } /// set password for ftp backend. - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { self.config.password = if password.is_empty() { None } else { @@ -499,27 +499,27 @@ mod build_test { #[test] fn test_build() { // ftps scheme, should suffix with default port 21 - let mut builder = FtpBuilder::default(); - builder.endpoint("ftps://ftp_server.local"); - let b = builder.build(); + let b = FtpBuilder::default() + .endpoint("ftps://ftp_server.local") + .build(); assert!(b.is_ok()); // ftp scheme - let mut builder = FtpBuilder::default(); - builder.endpoint("ftp://ftp_server.local:1234"); - let b = builder.build(); + let b = FtpBuilder::default() + .endpoint("ftp://ftp_server.local:1234") + .build(); assert!(b.is_ok()); // no scheme - let mut builder = FtpBuilder::default(); - builder.endpoint("ftp_server.local:8765"); - let b = builder.build(); + let b = FtpBuilder::default() + .endpoint("ftp_server.local:8765") + .build(); assert!(b.is_ok()); // invalid scheme - let mut builder = FtpBuilder::default(); - builder.endpoint("invalidscheme://ftp_server.local:8765"); - let b = builder.build(); + let b = FtpBuilder::default() + .endpoint("invalidscheme://ftp_server.local:8765") + .build(); assert!(b.is_err()); let e = b.unwrap_err(); assert_eq!(e.kind(), ErrorKind::ConfigInvalid); diff --git a/core/src/services/ftp/docs.md b/core/src/services/ftp/docs.md index 422f1a64dbb..39f5caa3c97 100644 --- a/core/src/services/ftp/docs.md +++ b/core/src/services/ftp/docs.md @@ -33,9 +33,8 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Ftp::default(); - - builder.endpoint("127.0.0.1"); + let mut builder = Ftp::default() + .endpoint("127.0.0.1"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/gcs/backend.rs b/core/src/services/gcs/backend.rs index f5443f0f15c..afeb38653d6 100644 --- a/core/src/services/gcs/backend.rs +++ b/core/src/services/gcs/backend.rs @@ -110,7 +110,7 @@ impl Debug for GcsBuilder { impl GcsBuilder { /// set the working directory root of backend - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -119,7 +119,7 @@ impl GcsBuilder { } /// set the container's name - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { self.config.bucket = bucket.to_string(); self } @@ -135,7 +135,7 @@ impl GcsBuilder { /// - full-control: `https://www.googleapis.com/auth/devstorage.full_control` /// /// Reference: [Cloud Storage authentication](https://cloud.google.com/storage/docs/authentication) - pub fn scope(&mut self, scope: &str) -> &mut Self { + pub fn scope(mut self, scope: &str) -> Self { if !scope.is_empty() { self.config.scope = Some(scope.to_string()) }; @@ -146,7 +146,7 @@ impl GcsBuilder { /// /// service account will be used for fetch token from vm metadata. /// If not set, we will try to fetch with `default` service account. - pub fn service_account(&mut self, service_account: &str) -> &mut Self { + pub fn service_account(mut self, service_account: &str) -> Self { if !service_account.is_empty() { self.config.service_account = Some(service_account.to_string()) }; @@ -154,7 +154,7 @@ impl GcsBuilder { } /// set the endpoint GCS service uses - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { self.config.endpoint = Some(endpoint.to_string()) }; @@ -168,7 +168,7 @@ impl GcsBuilder { /// we will use one of `credential` and `credential_path` to complete the OAuth2 authentication. /// /// Reference: [Google Cloud Storage Authentication](https://cloud.google.com/docs/authentication). - pub fn credential(&mut self, credential: &str) -> &mut Self { + pub fn credential(mut self, credential: &str) -> Self { if !credential.is_empty() { self.config.credential = Some(credential.to_string()) }; @@ -181,7 +181,7 @@ impl GcsBuilder { /// we will use one of `credential` and `credential_path` to complete the OAuth2 authentication. /// /// Reference: [Google Cloud Storage Authentication](https://cloud.google.com/docs/authentication). - pub fn credential_path(&mut self, path: &str) -> &mut Self { + pub fn credential_path(mut self, path: &str) -> Self { if !path.is_empty() { self.config.credential_path = Some(path.to_string()) }; @@ -194,13 +194,13 @@ impl GcsBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } /// Specify the customized token loader used by this service. - pub fn customized_token_loader(&mut self, token_load: Box) -> &mut Self { + pub fn customized_token_loader(mut self, token_load: Box) -> Self { self.customized_token_loader = Some(token_load); self } @@ -214,7 +214,7 @@ impl GcsBuilder { /// - `private` /// - `projectPrivate` /// - `publicRead` - pub fn predefined_acl(&mut self, acl: &str) -> &mut Self { + pub fn predefined_acl(mut self, acl: &str) -> Self { if !acl.is_empty() { self.config.predefined_acl = Some(acl.to_string()) }; @@ -228,7 +228,7 @@ impl GcsBuilder { /// - `NEARLINE` /// - `COLDLINE` /// - `ARCHIVE` - pub fn default_storage_class(&mut self, class: &str) -> &mut Self { + pub fn default_storage_class(mut self, class: &str) -> Self { if !class.is_empty() { self.config.default_storage_class = Some(class.to_string()) }; diff --git a/core/src/services/gcs/docs.md b/core/src/services/gcs/docs.md index a068f8b0919..58f00d4ac62 100644 --- a/core/src/services/gcs/docs.md +++ b/core/src/services/gcs/docs.md @@ -57,19 +57,18 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Gcs::default(); - - // set the storage bucket for OpenDAL - builder.bucket("test"); - // set the working directory root for GCS - // all operations will happen within it - builder.root("/path/to/dir"); - // set the credentials with service account - builder.credential("service account JSON in base64"); - // set the predefined ACL for GCS - builder.predefined_acl("publicRead"); - // set the default storage class for GCS - builder.default_storage_class("STANDARD"); + let mut builder = Gcs::default() + // set the storage bucket for OpenDAL + .bucket("test") + // set the working directory root for GCS + // all operations will happen within it + .root("/path/to/dir") + // set the credentials with service account + .credential("service account JSON in base64") + // set the predefined ACL for GCS + .predefined_acl("publicRead") + // set the default storage class for GCS + .default_storage_class("STANDARD"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/gdrive/builder.rs b/core/src/services/gdrive/builder.rs index 9f771d637a5..ab801c70f15 100644 --- a/core/src/services/gdrive/builder.rs +++ b/core/src/services/gdrive/builder.rs @@ -90,7 +90,7 @@ impl Debug for GdriveBuilder { impl GdriveBuilder { /// Set root path of GoogleDrive folder. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = Some(root.to_string()); self } @@ -105,7 +105,7 @@ impl GdriveBuilder { /// - An access token is valid for 1 hour. /// - If you want to use the access token for a long time, /// you can use the refresh token to get a new access token. - pub fn access_token(&mut self, access_token: &str) -> &mut Self { + pub fn access_token(mut self, access_token: &str) -> Self { self.config.access_token = Some(access_token.to_string()); self } @@ -115,7 +115,7 @@ impl GdriveBuilder { /// You can get the refresh token via OAuth 2.0 Flow of GoogleDrive API. /// /// OpenDAL will use this refresh token to get a new access token when the old one is expired. - pub fn refresh_token(&mut self, refresh_token: &str) -> &mut Self { + pub fn refresh_token(mut self, refresh_token: &str) -> Self { self.config.refresh_token = Some(refresh_token.to_string()); self } @@ -123,7 +123,7 @@ impl GdriveBuilder { /// Set the client id for GoogleDrive. /// /// This is required for OAuth 2.0 Flow to refresh the access token. - pub fn client_id(&mut self, client_id: &str) -> &mut Self { + pub fn client_id(mut self, client_id: &str) -> Self { self.config.client_id = Some(client_id.to_string()); self } @@ -131,7 +131,7 @@ impl GdriveBuilder { /// Set the client secret for GoogleDrive. /// /// This is required for OAuth 2.0 Flow with refresh the access token. - pub fn client_secret(&mut self, client_secret: &str) -> &mut Self { + pub fn client_secret(mut self, client_secret: &str) -> Self { self.config.client_secret = Some(client_secret.to_string()); self } @@ -142,7 +142,7 @@ impl GdriveBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, http_client: HttpClient) -> &mut Self { + pub fn http_client(mut self, http_client: HttpClient) -> Self { self.http_client = Some(http_client); self } diff --git a/core/src/services/gdrive/docs.md b/core/src/services/gdrive/docs.md index 851440b63bb..63544dc92f8 100644 --- a/core/src/services/gdrive/docs.md +++ b/core/src/services/gdrive/docs.md @@ -56,9 +56,9 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Gdrive::default(); - builder.root("/test"); - builder.access_token(""); + let mut builder = Gdrive::default() + .root("/test") + .access_token(""); Ok(()) } diff --git a/core/src/services/ghac/backend.rs b/core/src/services/ghac/backend.rs index 6a318d76123..7333f92184b 100644 --- a/core/src/services/ghac/backend.rs +++ b/core/src/services/ghac/backend.rs @@ -115,7 +115,7 @@ pub struct GhacBuilder { impl GhacBuilder { /// set the working directory root of backend - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -129,7 +129,7 @@ impl GhacBuilder { /// It's better to make sure this value is only used by this backend. /// /// If not set, we will use `opendal` as default. - pub fn version(&mut self, version: &str) -> &mut Self { + pub fn version(mut self, version: &str) -> Self { if !version.is_empty() { self.config.version = Some(version.to_string()) } @@ -142,7 +142,7 @@ impl GhacBuilder { /// For example, this is provided as the `ACTIONS_CACHE_URL` environment variable by the GHA runner. /// /// Default: the value of the `ACTIONS_CACHE_URL` environment variable. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { self.config.endpoint = Some(endpoint.to_string()) } @@ -155,7 +155,7 @@ impl GhacBuilder { /// runner. /// /// Default: the value of the `ACTIONS_RUNTIME_TOKEN` environment variable. - pub fn runtime_token(&mut self, runtime_token: &str) -> &mut Self { + pub fn runtime_token(mut self, runtime_token: &str) -> Self { if !runtime_token.is_empty() { self.config.runtime_token = Some(runtime_token.to_string()) } @@ -168,7 +168,7 @@ impl GhacBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/ghac/docs.md b/core/src/services/ghac/docs.md index 0a07fee97a4..c1ead3fbc82 100644 --- a/core/src/services/ghac/docs.md +++ b/core/src/services/ghac/docs.md @@ -71,11 +71,11 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create ghac backend builder. - let mut builder = Ghac::default(); - // Set the root for ghac, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/path/to/dir"); + let mut builder = Ghac::default() + // Set the root for ghac, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/path/to/dir"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/github/backend.rs b/core/src/services/github/backend.rs index e25cc96a37b..b45fefe9838 100644 --- a/core/src/services/github/backend.rs +++ b/core/src/services/github/backend.rs @@ -102,7 +102,7 @@ impl GithubBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -115,21 +115,21 @@ impl GithubBuilder { /// Github access_token. /// /// required. - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { self.config.token = Some(token.to_string()); self } /// Set Github repo owner. - pub fn owner(&mut self, owner: &str) -> &mut Self { + pub fn owner(mut self, owner: &str) -> Self { self.config.owner = owner.to_string(); self } /// Set Github repo name. - pub fn repo(&mut self, repo: &str) -> &mut Self { + pub fn repo(mut self, repo: &str) -> Self { self.config.repo = repo.to_string(); self @@ -141,7 +141,7 @@ impl GithubBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/github/docs.md b/core/src/services/github/docs.md index 1f48c911a85..d7c63a841fd 100644 --- a/core/src/services/github/docs.md +++ b/core/src/services/github/docs.md @@ -34,16 +34,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Github::default(); - - // set the storage root for OpenDAL - builder.root("/"); - // set the access token for Github API - builder.token("your_access_token"); - // set the owner for Github - builder.owner("your_owner"); - // set the repository for Github - builder.repo("your_repo"); + let mut builder = Github::default() + // set the storage root for OpenDAL + .root("/") + // set the access token for Github API + .token("your_access_token") + // set the owner for Github + .owner("your_owner") + // set the repository for Github + .repo("your_repo"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/gridfs/backend.rs b/core/src/services/gridfs/backend.rs index d00d54ddacc..a22641c9f24 100644 --- a/core/src/services/gridfs/backend.rs +++ b/core/src/services/gridfs/backend.rs @@ -103,7 +103,7 @@ impl GridFsBuilder { /// - ... (any other options you wish to highlight) /// /// For more information, please refer to [MongoDB Connection String URI Format](https://docs.mongodb.com/manual/reference/connection-string/). - pub fn connection_string(&mut self, v: &str) -> &mut Self { + pub fn connection_string(mut self, v: &str) -> Self { if !v.is_empty() { self.config.connection_string = Some(v.to_string()); } @@ -113,7 +113,7 @@ impl GridFsBuilder { /// Set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } @@ -121,7 +121,7 @@ impl GridFsBuilder { } /// Set the database name of the MongoDB GridFs service to read/write. - pub fn database(&mut self, database: &str) -> &mut Self { + pub fn database(mut self, database: &str) -> Self { if !database.is_empty() { self.config.database = Some(database.to_string()); } @@ -131,7 +131,7 @@ impl GridFsBuilder { /// Set the bucket name of the MongoDB GridFs service to read/write. /// /// Default to `fs` if not specified. - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { if !bucket.is_empty() { self.config.bucket = Some(bucket.to_string()); } @@ -141,7 +141,7 @@ impl GridFsBuilder { /// Set the chunk size of the MongoDB GridFs service used to break the user file into chunks. /// /// Default to `255 KiB` if not specified. - pub fn chunk_size(&mut self, chunk_size: u32) -> &mut Self { + pub fn chunk_size(mut self, chunk_size: u32) -> Self { if chunk_size > 0 { self.config.chunk_size = Some(chunk_size); } diff --git a/core/src/services/gridfs/docs.md b/core/src/services/gridfs/docs.md index 9e6e5a458db..74bbae06d7a 100644 --- a/core/src/services/gridfs/docs.md +++ b/core/src/services/gridfs/docs.md @@ -32,13 +32,13 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Gridfs::default(); - builder.root("/"); - builder.connection_string("mongodb://myUser:myPassword@localhost:27017/myAuthDB"); - builder.database("your_database"); - builder.bucket("your_bucket"); - // The chunk size in bytes used to break the user file into chunks. - builder.chunk_size(255); + let mut builder = Gridfs::default() + .root("/") + .connection_string("mongodb://myUser:myPassword@localhost:27017/myAuthDB") + .database("your_database") + .bucket("your_bucket") + // The chunk size in bytes used to break the user file into chunks. + .chunk_size(255); let op = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/hdfs/backend.rs b/core/src/services/hdfs/backend.rs index 17306bd4620..50b1dbbc323 100644 --- a/core/src/services/hdfs/backend.rs +++ b/core/src/services/hdfs/backend.rs @@ -95,7 +95,7 @@ impl HdfsBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -111,7 +111,7 @@ impl HdfsBuilder { /// /// - `default`: using the default setting based on hadoop config. /// - `hdfs://127.0.0.1:9000`: connect to hdfs cluster. - pub fn name_node(&mut self, name_node: &str) -> &mut Self { + pub fn name_node(mut self, name_node: &str) -> Self { if !name_node.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.name_node = Some(name_node.trim_end_matches('/').to_string()) @@ -123,7 +123,7 @@ impl HdfsBuilder { /// Set kerberos_ticket_cache_path of this backend /// /// This should be configured when kerberos is enabled. - pub fn kerberos_ticket_cache_path(&mut self, kerberos_ticket_cache_path: &str) -> &mut Self { + pub fn kerberos_ticket_cache_path(mut self, kerberos_ticket_cache_path: &str) -> Self { if !kerberos_ticket_cache_path.is_empty() { self.config.kerberos_ticket_cache_path = Some(kerberos_ticket_cache_path.to_string()) } @@ -131,7 +131,7 @@ impl HdfsBuilder { } /// Set user of this backend - pub fn user(&mut self, user: &str) -> &mut Self { + pub fn user(mut self, user: &str) -> Self { if !user.is_empty() { self.config.user = Some(user.to_string()) } @@ -141,7 +141,7 @@ impl HdfsBuilder { /// Enable append capacity of this backend. /// /// This should be disabled when HDFS runs in non-distributed mode. - pub fn enable_append(&mut self, enable_append: bool) -> &mut Self { + pub fn enable_append(mut self, enable_append: bool) -> Self { self.config.enable_append = enable_append; self } @@ -152,7 +152,7 @@ impl HdfsBuilder { /// /// - When append is enabled, we will not use atomic write /// to avoid data loss and performance issue. - pub fn atomic_write_dir(&mut self, dir: &str) -> &mut Self { + pub fn atomic_write_dir(mut self, dir: &str) -> Self { self.config.atomic_write_dir = if dir.is_empty() { None } else { diff --git a/core/src/services/hdfs/docs.md b/core/src/services/hdfs/docs.md index 8bf1394553a..5d0f98bbadf 100644 --- a/core/src/services/hdfs/docs.md +++ b/core/src/services/hdfs/docs.md @@ -118,19 +118,19 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create fs backend builder. - let mut builder = Hdfs::default(); - // Set the name node for hdfs. - // If the string starts with a protocol type such as file://, hdfs://, or gs://, this protocol type will be used. - builder.name_node("hdfs://127.0.0.1:9000"); - // Set the root for hdfs, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/tmp"); - - // Enable the append capacity for hdfs. - // - // Note: HDFS run in non-distributed mode doesn't support append. - builder.enable_append(true); + let mut builder = Hdfs::default() + // Set the name node for hdfs. + // If the string starts with a protocol type such as file://, hdfs://, or gs://, this protocol type will be used. + .name_node("hdfs://127.0.0.1:9000") + // Set the root for hdfs, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/tmp") + + // Enable the append capacity for hdfs. + // + // Note: HDFS run in non-distributed mode doesn't support append. + .enable_append(true); // `Accessor` provides the low level APIs, we will use `Operator` normally. let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/hdfs_native/backend.rs b/core/src/services/hdfs_native/backend.rs index 937f3a977ce..de7d830a8ed 100644 --- a/core/src/services/hdfs_native/backend.rs +++ b/core/src/services/hdfs_native/backend.rs @@ -82,7 +82,7 @@ impl HdfsNativeBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -98,7 +98,7 @@ impl HdfsNativeBuilder { /// /// - `default`: using the default setting based on hadoop config. /// - `hdfs://127.0.0.1:9000`: connect to hdfs cluster. - pub fn url(&mut self, url: &str) -> &mut Self { + pub fn url(mut self, url: &str) -> Self { if !url.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.url = Some(url.trim_end_matches('/').to_string()) @@ -110,7 +110,7 @@ impl HdfsNativeBuilder { /// Enable append capacity of this backend. /// /// This should be disabled when HDFS runs in non-distributed mode. - pub fn enable_append(&mut self, enable_append: bool) -> &mut Self { + pub fn enable_append(mut self, enable_append: bool) -> Self { self.config.enable_append = enable_append; self } diff --git a/core/src/services/http/backend.rs b/core/src/services/http/backend.rs index c49f69d20b4..dfd6efd140f 100644 --- a/core/src/services/http/backend.rs +++ b/core/src/services/http/backend.rs @@ -89,7 +89,7 @@ impl HttpBuilder { /// Set endpoint for http backend. /// /// For example: `https://example.com` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -102,7 +102,7 @@ impl HttpBuilder { /// set username for http backend /// /// default: no username - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(mut self, username: &str) -> Self { if !username.is_empty() { self.config.username = Some(username.to_owned()); } @@ -112,7 +112,7 @@ impl HttpBuilder { /// set password for http backend /// /// default: no password - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { if !password.is_empty() { self.config.password = Some(password.to_owned()); } @@ -122,7 +122,7 @@ impl HttpBuilder { /// set bearer token for http backend /// /// default: no access token - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { self.config.token = Some(token.to_owned()); } @@ -130,7 +130,7 @@ impl HttpBuilder { } /// Set root path of http backend. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -146,7 +146,7 @@ impl HttpBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/http/docs.md b/core/src/services/http/docs.md index 0dc2ac83cad..c792309f968 100644 --- a/core/src/services/http/docs.md +++ b/core/src/services/http/docs.md @@ -37,9 +37,7 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create http backend builder - let mut builder = Http::default(); - - builder.endpoint("127.0.0.1"); + let mut builder = Http::default().endpoint("127.0.0.1"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/huggingface/backend.rs b/core/src/services/huggingface/backend.rs index 4fc9e321b59..5b025197d70 100644 --- a/core/src/services/huggingface/backend.rs +++ b/core/src/services/huggingface/backend.rs @@ -117,7 +117,7 @@ impl HuggingfaceBuilder { /// /// Currently, only models and datasets are supported. /// [Reference](https://huggingface.co/docs/hub/repositories) - pub fn repo_type(&mut self, repo_type: &str) -> &mut Self { + pub fn repo_type(mut self, repo_type: &str) -> Self { if !repo_type.is_empty() { self.config.repo_type = Some(repo_type.to_string()); } @@ -133,7 +133,7 @@ impl HuggingfaceBuilder { /// /// Dataset's repo id looks like: /// - databricks/databricks-dolly-15k - pub fn repo_id(&mut self, repo_id: &str) -> &mut Self { + pub fn repo_id(mut self, repo_id: &str) -> Self { if !repo_id.is_empty() { self.config.repo_id = Some(repo_id.to_string()); } @@ -147,7 +147,7 @@ impl HuggingfaceBuilder { /// For example, revision can be: /// - main /// - 1d0c4eb - pub fn revision(&mut self, revision: &str) -> &mut Self { + pub fn revision(mut self, revision: &str) -> Self { if !revision.is_empty() { self.config.revision = Some(revision.to_string()); } @@ -157,7 +157,7 @@ impl HuggingfaceBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()); } @@ -167,7 +167,7 @@ impl HuggingfaceBuilder { /// Set the token of this backend. /// /// This is optional. - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { self.config.token = Some(token.to_string()); } diff --git a/core/src/services/huggingface/docs.md b/core/src/services/huggingface/docs.md index b7987e69281..e08d4bf68ea 100644 --- a/core/src/services/huggingface/docs.md +++ b/core/src/services/huggingface/docs.md @@ -42,18 +42,17 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create Huggingface backend builder - let mut builder = Huggingface::default(); - - // set the type of Huggingface repository - builder.repo_type("dataset"); - // set the id of Huggingface repository - builder.repo_id("databricks/databricks-dolly-15k"); - // set the revision of Huggingface repository - builder.revision("main"); - // set the root for Huggingface, all operations will happen under this root - builder.root("/path/to/dir"); - // set the token for accessing the repository - builder.token("access_token"); + let mut builder = Huggingface::default() + // set the type of Huggingface repository + .repo_type("dataset") + // set the id of Huggingface repository + .repo_id("databricks/databricks-dolly-15k") + // set the revision of Huggingface repository + .revision("main") + // set the root for Huggingface, all operations will happen under this root + .root("/path/to/dir") + // set the token for accessing the repository + .token("access_token"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/icloud/backend.rs b/core/src/services/icloud/backend.rs index 0e2c07a62e4..37b8146c7a1 100644 --- a/core/src/services/icloud/backend.rs +++ b/core/src/services/icloud/backend.rs @@ -108,7 +108,7 @@ impl IcloudBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -121,7 +121,7 @@ impl IcloudBuilder { /// Your Apple id /// /// It is required. your Apple login email, e.g. `example@gmail.com` - pub fn apple_id(&mut self, apple_id: &str) -> &mut Self { + pub fn apple_id(mut self, apple_id: &str) -> Self { self.config.apple_id = if apple_id.is_empty() { None } else { @@ -134,7 +134,7 @@ impl IcloudBuilder { /// Your Apple id password /// /// It is required. your icloud login password, e.g. `password` - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { self.config.password = if password.is_empty() { None } else { @@ -147,7 +147,7 @@ impl IcloudBuilder { /// Trust token and ds_web_auth_token is used for temporary access to the icloudDrive API. /// /// Authenticate using session token - pub fn trust_token(&mut self, trust_token: &str) -> &mut Self { + pub fn trust_token(mut self, trust_token: &str) -> Self { self.config.trust_token = if trust_token.is_empty() { None } else { @@ -160,7 +160,7 @@ impl IcloudBuilder { /// ds_web_auth_token must be set in Session /// /// Avoid Two Factor Authentication - pub fn ds_web_auth_token(&mut self, ds_web_auth_token: &str) -> &mut Self { + pub fn ds_web_auth_token(mut self, ds_web_auth_token: &str) -> Self { self.config.ds_web_auth_token = if ds_web_auth_token.is_empty() { None } else { @@ -174,7 +174,7 @@ impl IcloudBuilder { /// /// If in china mainland, we will connect to `https://www.icloud.com.cn`. /// Otherwise, we will connect to `https://www.icloud.com`. - pub fn is_china_mainland(&mut self, is_china_mainland: bool) -> &mut Self { + pub fn is_china_mainland(mut self, is_china_mainland: bool) -> Self { self.config.is_china_mainland = is_china_mainland; self } @@ -185,7 +185,7 @@ impl IcloudBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/icloud/docs.md b/core/src/services/icloud/docs.md index 46f7cbabd8f..741a9c3c956 100644 --- a/core/src/services/icloud/docs.md +++ b/core/src/services/icloud/docs.md @@ -53,13 +53,13 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Icloud::default(); - builder.root("/"); - builder.apple_id(""); - builder.password(""); - builder.trust_token(""); - builder.ds_web_auth_token(""); - builder.is_china_mainland(true); + let mut builder = Icloud::default() + .root("/") + .apple_id("") + .password("") + .trust_token("") + .ds_web_auth_token("") + .is_china_mainland(true); Ok(()) } diff --git a/core/src/services/ipfs/backend.rs b/core/src/services/ipfs/backend.rs index dfab7978b5a..b9ffda9791a 100644 --- a/core/src/services/ipfs/backend.rs +++ b/core/src/services/ipfs/backend.rs @@ -68,7 +68,7 @@ impl IpfsBuilder { /// - `/ipfs/QmPpCt1aYGb9JWJRmXRUnmJtVgeFFTJGzWFYEEX7bo9zGJ/` (IPFS with CID v0) /// - `/ipfs/bafybeibozpulxtpv5nhfa2ue3dcjx23ndh3gwr5vwllk7ptoyfwnfjjr4q/` (IPFS with CID v1) /// - `/ipns/opendal.apache.org/` (IPNS) - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -87,7 +87,7 @@ impl IpfsBuilder { /// - `https://dweb.link` /// - `https://cloudflare-ipfs.com` /// - `http://127.0.0.1:8080` (ipfs daemon in local) - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()); @@ -102,7 +102,7 @@ impl IpfsBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/ipfs/docs.md b/core/src/services/ipfs/docs.md index e1e0cb91845..331ec901306 100644 --- a/core/src/services/ipfs/docs.md +++ b/core/src/services/ipfs/docs.md @@ -32,12 +32,11 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Ipfs::default(); - - // set the endpoint for OpenDAL - builder.endpoint("https://ipfs.io"); - // set the root for OpenDAL - builder.root("/ipfs/QmPpCt1aYGb9JWJRmXRUnmJtVgeFFTJGzWFYEEX7bo9zGJ"); + let mut builder = Ipfs::default() + // set the endpoint for OpenDAL + .endpoint("https://ipfs.io") + // set the root for OpenDAL + .root("/ipfs/QmPpCt1aYGb9JWJRmXRUnmJtVgeFFTJGzWFYEEX7bo9zGJ"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/ipmfs/builder.rs b/core/src/services/ipmfs/builder.rs index 6bf738ddcbf..ab6f150ae35 100644 --- a/core/src/services/ipmfs/builder.rs +++ b/core/src/services/ipmfs/builder.rs @@ -74,10 +74,9 @@ impl Configurator for IpmfsConfig { /// #[tokio::main] /// async fn main() -> Result<()> { /// // create backend builder -/// let mut builder = Ipmfs::default(); -/// -/// // set the storage bucket for OpenDAL -/// builder.endpoint("http://127.0.0.1:5001"); +/// let mut builder = Ipmfs::default() +/// // set the storage bucket for OpenDAL +/// .endpoint("http://127.0.0.1:5001"); /// /// let op: Operator = Operator::new(builder)?.finish(); /// @@ -92,7 +91,7 @@ pub struct IpmfsBuilder { impl IpmfsBuilder { /// Set root for ipfs. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -105,7 +104,7 @@ impl IpmfsBuilder { /// Set endpoint for ipfs. /// /// Default: http://localhost:5001 - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -120,7 +119,7 @@ impl IpmfsBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/koofr/backend.rs b/core/src/services/koofr/backend.rs index 29b72e1451b..71728c15efc 100644 --- a/core/src/services/koofr/backend.rs +++ b/core/src/services/koofr/backend.rs @@ -38,7 +38,7 @@ use super::writer::KoofrWriters; use crate::raw::*; use crate::*; -/// Config for backblaze Koofr services support. +/// Config for Koofr services support. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -97,7 +97,7 @@ impl KoofrBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -110,7 +110,7 @@ impl KoofrBuilder { /// endpoint. /// /// It is required. e.g. `https://api.koofr.net/` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = endpoint.to_string(); self @@ -119,7 +119,7 @@ impl KoofrBuilder { /// email. /// /// It is required. e.g. `test@example.com` - pub fn email(&mut self, email: &str) -> &mut Self { + pub fn email(mut self, email: &str) -> Self { self.config.email = email.to_string(); self @@ -135,7 +135,7 @@ impl KoofrBuilder { /// This is not user's Koofr account password. /// Please use the application password instead. /// Please also remind users of this. - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { self.config.password = if password.is_empty() { None } else { @@ -151,7 +151,7 @@ impl KoofrBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/koofr/docs.md b/core/src/services/koofr/docs.md index 0366b32efd3..b8dbdca3d29 100644 --- a/core/src/services/koofr/docs.md +++ b/core/src/services/koofr/docs.md @@ -34,16 +34,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Koofr::default(); - - // set the storage bucket for OpenDAL - builder.root("/"); - // set the bucket for OpenDAL - builder.endpoint("https://api.koofr.net/"); - // set the email for OpenDAL - builder.email("me@example.com"); - // set the password for OpenDAL - builder.password("xxx xxx xxx xxx"); + let mut builder = Koofr::default() + // set the storage bucket for OpenDAL + .root("/") + // set the bucket for OpenDAL + .endpoint("https://api.koofr.net/") + // set the email for OpenDAL + .email("me@example.com") + // set the password for OpenDAL + .password("xxx xxx xxx xxx"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/libsql/backend.rs b/core/src/services/libsql/backend.rs index 731ad866c18..8cf007902ef 100644 --- a/core/src/services/libsql/backend.rs +++ b/core/src/services/libsql/backend.rs @@ -43,7 +43,7 @@ use crate::raw::adapters::kv; use crate::raw::*; use crate::*; -/// Config for Libsqlservices support. +/// Config for Libsql services support. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -115,7 +115,7 @@ impl LibsqlBuilder { /// - `http://example.com/db` /// - `https://example.com/db` /// - `libsql://example.com/db` - pub fn connection_string(&mut self, v: &str) -> &mut Self { + pub fn connection_string(mut self, v: &str) -> Self { if !v.is_empty() { self.config.connection_string = Some(v.to_string()); } @@ -125,7 +125,7 @@ impl LibsqlBuilder { /// set the authentication token for libsql service. /// /// default: no authentication token - pub fn auth_token(&mut self, auth_token: &str) -> &mut Self { + pub fn auth_token(mut self, auth_token: &str) -> Self { if !auth_token.is_empty() { self.config.auth_token = Some(auth_token.to_owned()); } @@ -135,7 +135,7 @@ impl LibsqlBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()); } @@ -143,7 +143,7 @@ impl LibsqlBuilder { } /// Set the table name of the libsql service to read/write. - pub fn table(&mut self, table: &str) -> &mut Self { + pub fn table(mut self, table: &str) -> Self { if !table.is_empty() { self.config.table = Some(table.to_string()); } @@ -153,7 +153,7 @@ impl LibsqlBuilder { /// Set the key field name of the libsql service to read/write. /// /// Default to `key` if not specified. - pub fn key_field(&mut self, key_field: &str) -> &mut Self { + pub fn key_field(mut self, key_field: &str) -> Self { if !key_field.is_empty() { self.config.key_field = Some(key_field.to_string()); } @@ -163,7 +163,7 @@ impl LibsqlBuilder { /// Set the value field name of the libsql service to read/write. /// /// Default to `value` if not specified. - pub fn value_field(&mut self, value_field: &str) -> &mut Self { + pub fn value_field(mut self, value_field: &str) -> Self { if !value_field.is_empty() { self.config.value_field = Some(value_field.to_string()); } diff --git a/core/src/services/libsql/docs.md b/core/src/services/libsql/docs.md index 36535007645..61ad5b3cf59 100644 --- a/core/src/services/libsql/docs.md +++ b/core/src/services/libsql/docs.md @@ -33,15 +33,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Libsql::default(); - builder.root("/"); - builder.connection_string("https://example.com/db"); - builder.auth_token("secret"); - builder.table("your_table"); - // key field type in the table should be compatible with Rust's &str like text - builder.key_field("key"); - // value field type in the table should be compatible with Rust's Vec like bytea - builder.value_field("value"); + let mut builder = Libsql::default() + .root("/") + .connection_string("https://example.com/db") + .auth_token("secret") + .table("your_table") + // key field type in the table should be compatible with Rust's &str like text + .key_field("key") + // value field type in the table should be compatible with Rust's Vec like bytea + .value_field("value"); let op = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/memcached/backend.rs b/core/src/services/memcached/backend.rs index 3f26f4c0099..fc65b9ef97e 100644 --- a/core/src/services/memcached/backend.rs +++ b/core/src/services/memcached/backend.rs @@ -66,7 +66,7 @@ impl MemcachedBuilder { /// set the network address of memcached service. /// /// For example: "tcp://localhost:11211" - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { self.config.endpoint = Some(endpoint.to_owned()); } @@ -76,7 +76,7 @@ impl MemcachedBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } @@ -84,19 +84,19 @@ impl MemcachedBuilder { } /// set the username. - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(mut self, username: &str) -> Self { self.config.username = Some(username.to_string()); self } /// set the password. - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { self.config.password = Some(password.to_string()); self } /// Set the default ttl for memcached services. - pub fn default_ttl(&mut self, ttl: Duration) -> &mut Self { + pub fn default_ttl(mut self, ttl: Duration) -> Self { self.config.default_ttl = Some(ttl); self } diff --git a/core/src/services/memcached/docs.md b/core/src/services/memcached/docs.md index 42b8285ae96..40de9df81ce 100644 --- a/core/src/services/memcached/docs.md +++ b/core/src/services/memcached/docs.md @@ -35,12 +35,11 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create memcached backend builder - let mut builder = Memcached::default(); - - builder.endpoint("tcp://127.0.0.1:11211"); - // if you enable authentication, set username and password for authentication - // builder.username("admin"); - // builder.password("password"); + let mut builder = Memcached::default() + .endpoint("tcp://127.0.0.1:11211"); + // if you enable authentication, set username and password for authentication + // builder.username("admin") + // builder.password("password"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/memory/backend.rs b/core/src/services/memory/backend.rs index 70866242d9e..5e922f3214b 100644 --- a/core/src/services/memory/backend.rs +++ b/core/src/services/memory/backend.rs @@ -27,7 +27,7 @@ use crate::raw::adapters::typed_kv; use crate::raw::Access; use crate::*; -///Config for memory. +/// Config for memory. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -51,7 +51,7 @@ pub struct MemoryBuilder { impl MemoryBuilder { /// Set the root for BTreeMap. - pub fn root(&mut self, path: &str) -> &mut Self { + pub fn root(mut self, path: &str) -> Self { self.config.root = Some(path.into()); self } diff --git a/core/src/services/memory/docs.md b/core/src/services/memory/docs.md index c419545f848..5ce257ea56d 100644 --- a/core/src/services/memory/docs.md +++ b/core/src/services/memory/docs.md @@ -27,8 +27,7 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Memory::default(); - builder.root("/tmp"); + let mut builder = Memory::default().root("/tmp"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/mini_moka/backend.rs b/core/src/services/mini_moka/backend.rs index 8b3cc203a11..9cb0a1773bc 100644 --- a/core/src/services/mini_moka/backend.rs +++ b/core/src/services/mini_moka/backend.rs @@ -64,7 +64,7 @@ impl MiniMokaBuilder { /// Sets the max capacity of the cache. /// /// Refer to [`mini-moka::sync::CacheBuilder::max_capacity`](https://docs.rs/mini-moka/latest/mini_moka/sync/struct.CacheBuilder.html#method.max_capacity) - pub fn max_capacity(&mut self, v: u64) -> &mut Self { + pub fn max_capacity(mut self, v: u64) -> Self { if v != 0 { self.config.max_capacity = Some(v); } @@ -74,7 +74,7 @@ impl MiniMokaBuilder { /// Sets the time to live of the cache. /// /// Refer to [`mini-moka::sync::CacheBuilder::time_to_live`](https://docs.rs/mini-moka/latest/mini_moka/sync/struct.CacheBuilder.html#method.time_to_live) - pub fn time_to_live(&mut self, v: Duration) -> &mut Self { + pub fn time_to_live(mut self, v: Duration) -> Self { if !v.is_zero() { self.config.time_to_live = Some(v); } @@ -84,7 +84,7 @@ impl MiniMokaBuilder { /// Sets the time to idle of the cache. /// /// Refer to [`mini-moka::sync::CacheBuilder::time_to_idle`](https://docs.rs/mini-moka/latest/mini_moka/sync/struct.CacheBuilder.html#method.time_to_idle) - pub fn time_to_idle(&mut self, v: Duration) -> &mut Self { + pub fn time_to_idle(mut self, v: Duration) -> Self { if !v.is_zero() { self.config.time_to_idle = Some(v); } diff --git a/core/src/services/moka/backend.rs b/core/src/services/moka/backend.rs index b6565998b27..7ad68a17609 100644 --- a/core/src/services/moka/backend.rs +++ b/core/src/services/moka/backend.rs @@ -29,7 +29,7 @@ use crate::raw::adapters::typed_kv; use crate::raw::*; use crate::*; -/// Config for Mokaservices support. +/// Config for Moka services support. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -81,7 +81,7 @@ pub struct MokaBuilder { impl MokaBuilder { /// Name for this cache instance. - pub fn name(&mut self, v: &str) -> &mut Self { + pub fn name(mut self, v: &str) -> Self { if !v.is_empty() { self.config.name = Some(v.to_owned()); } @@ -91,7 +91,7 @@ impl MokaBuilder { /// Sets the max capacity of the cache. /// /// Refer to [`moka::sync::CacheBuilder::max_capacity`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.max_capacity) - pub fn max_capacity(&mut self, v: u64) -> &mut Self { + pub fn max_capacity(mut self, v: u64) -> Self { if v != 0 { self.config.max_capacity = Some(v); } @@ -101,7 +101,7 @@ impl MokaBuilder { /// Sets the time to live of the cache. /// /// Refer to [`moka::sync::CacheBuilder::time_to_live`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.time_to_live) - pub fn time_to_live(&mut self, v: Duration) -> &mut Self { + pub fn time_to_live(mut self, v: Duration) -> Self { if !v.is_zero() { self.config.time_to_live = Some(v); } @@ -111,7 +111,7 @@ impl MokaBuilder { /// Sets the time to idle of the cache. /// /// Refer to [`moka::sync::CacheBuilder::time_to_idle`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.time_to_idle) - pub fn time_to_idle(&mut self, v: Duration) -> &mut Self { + pub fn time_to_idle(mut self, v: Duration) -> Self { if !v.is_zero() { self.config.time_to_idle = Some(v); } @@ -121,7 +121,7 @@ impl MokaBuilder { /// Sets the segments number of the cache. /// /// Refer to [`moka::sync::CacheBuilder::segments`](https://docs.rs/moka/latest/moka/sync/struct.CacheBuilder.html#method.segments) - pub fn segments(&mut self, v: usize) -> &mut Self { + pub fn segments(mut self, v: usize) -> Self { assert!(v != 0); self.config.num_segments = Some(v); self diff --git a/core/src/services/moka/docs.md b/core/src/services/moka/docs.md index d053b09a9fc..8f23d915bf0 100644 --- a/core/src/services/moka/docs.md +++ b/core/src/services/moka/docs.md @@ -34,8 +34,8 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Moka::default(); - builder.name("opendal"); + let mut builder = Moka::default() + .name("opendal"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/mongodb/backend.rs b/core/src/services/mongodb/backend.rs index 8f7cceed6e4..963b31fd8f1 100644 --- a/core/src/services/mongodb/backend.rs +++ b/core/src/services/mongodb/backend.rs @@ -104,7 +104,7 @@ impl MongodbBuilder { /// - ... (any other options you wish to highlight) /// /// For more information, please refer to [MongoDB Connection String URI Format](https://docs.mongodb.com/manual/reference/connection-string/). - pub fn connection_string(&mut self, v: &str) -> &mut Self { + pub fn connection_string(mut self, v: &str) -> Self { if !v.is_empty() { self.config.connection_string = Some(v.to_string()); } @@ -113,7 +113,7 @@ impl MongodbBuilder { /// Set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } @@ -121,7 +121,7 @@ impl MongodbBuilder { } /// Set the database name of the MongoDB service to read/write. - pub fn database(&mut self, database: &str) -> &mut Self { + pub fn database(mut self, database: &str) -> Self { if !database.is_empty() { self.config.database = Some(database.to_string()); } @@ -129,7 +129,7 @@ impl MongodbBuilder { } /// Set the collection name of the MongoDB service to read/write. - pub fn collection(&mut self, collection: &str) -> &mut Self { + pub fn collection(mut self, collection: &str) -> Self { if !collection.is_empty() { self.config.collection = Some(collection.to_string()); } @@ -139,7 +139,7 @@ impl MongodbBuilder { /// Set the key field name of the MongoDB service to read/write. /// /// Default to `key` if not specified. - pub fn key_field(&mut self, key_field: &str) -> &mut Self { + pub fn key_field(mut self, key_field: &str) -> Self { if !key_field.is_empty() { self.config.key_field = Some(key_field.to_string()); } @@ -149,7 +149,7 @@ impl MongodbBuilder { /// Set the value field name of the MongoDB service to read/write. /// /// Default to `value` if not specified. - pub fn value_field(&mut self, value_field: &str) -> &mut Self { + pub fn value_field(mut self, value_field: &str) -> Self { if !value_field.is_empty() { self.config.value_field = Some(value_field.to_string()); } diff --git a/core/src/services/mongodb/docs.md b/core/src/services/mongodb/docs.md index d2434532dab..2c90995ec86 100644 --- a/core/src/services/mongodb/docs.md +++ b/core/src/services/mongodb/docs.md @@ -33,15 +33,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Mongodb::default(); - builder.root("/"); - builder.connection_string("mongodb://myUser:myPassword@localhost:27017/myAuthDB"); - builder.database("your_database"); - builder.collection("your_collection"); - // key field type in the table should be compatible with Rust's &str like text - builder.key_field("key"); - // value field type in the table should be compatible with Rust's Vec like bytea - builder.value_field("value"); + let mut builder = Mongodb::default() + .root("/") + .connection_string("mongodb://myUser:myPassword@localhost:27017/myAuthDB") + .database("your_database") + .collection("your_collection") + // key field type in the table should be compatible with Rust's &str like text + .key_field("key") + // value field type in the table should be compatible with Rust's Vec like bytea + .value_field("value"); let op = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/monoiofs/backend.rs b/core/src/services/monoiofs/backend.rs index 1d5208d5465..e0502693301 100644 --- a/core/src/services/monoiofs/backend.rs +++ b/core/src/services/monoiofs/backend.rs @@ -57,7 +57,7 @@ impl MonoiofsBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { diff --git a/core/src/services/monoiofs/docs.md b/core/src/services/monoiofs/docs.md index 47b0d5d8f04..f81ef4d731c 100644 --- a/core/src/services/monoiofs/docs.md +++ b/core/src/services/monoiofs/docs.md @@ -32,11 +32,11 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create monoiofs backend builder. - let mut builder = Monoiofs::default(); - // Set the root for monoiofs, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/tmp"); + let mut builder = Monoiofs::default() + // Set the root for monoiofs, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/tmp"); // `Accessor` provides the low level APIs, we will use `Operator` normally. let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/mysql/backend.rs b/core/src/services/mysql/backend.rs index 18ba0964617..b5e6179c5b0 100644 --- a/core/src/services/mysql/backend.rs +++ b/core/src/services/mysql/backend.rs @@ -96,7 +96,7 @@ impl MysqlBuilder { /// - `mysql://user:password@localhost:3306/db` /// /// For more information, please refer to [mysql client](https://dev.mysql.com/doc/refman/8.0/en/connecting-using-uri-or-key-value-pairs.html) - pub fn connection_string(&mut self, v: &str) -> &mut Self { + pub fn connection_string(mut self, v: &str) -> Self { if !v.is_empty() { self.config.connection_string = Some(v.to_string()); } @@ -106,7 +106,7 @@ impl MysqlBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()); } @@ -114,7 +114,7 @@ impl MysqlBuilder { } /// Set the table name of the mysql service to read/write. - pub fn table(&mut self, table: &str) -> &mut Self { + pub fn table(mut self, table: &str) -> Self { if !table.is_empty() { self.config.table = Some(table.to_string()); } @@ -124,7 +124,7 @@ impl MysqlBuilder { /// Set the key field name of the mysql service to read/write. /// /// Default to `key` if not specified. - pub fn key_field(&mut self, key_field: &str) -> &mut Self { + pub fn key_field(mut self, key_field: &str) -> Self { if !key_field.is_empty() { self.config.key_field = Some(key_field.to_string()); } @@ -134,7 +134,7 @@ impl MysqlBuilder { /// Set the value field name of the mysql service to read/write. /// /// Default to `value` if not specified. - pub fn value_field(&mut self, value_field: &str) -> &mut Self { + pub fn value_field(mut self, value_field: &str) -> Self { if !value_field.is_empty() { self.config.value_field = Some(value_field.to_string()); } diff --git a/core/src/services/mysql/docs.md b/core/src/services/mysql/docs.md index ef310c4c67e..7b38455c92c 100644 --- a/core/src/services/mysql/docs.md +++ b/core/src/services/mysql/docs.md @@ -32,14 +32,14 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Mysql::default(); - builder.root("/"); - builder.connection_string("mysql://you_username:your_password@127.0.0.1:5432/your_database"); - builder.table("your_table"); - // key field type in the table should be compatible with Rust's &str like text - builder.key_field("key"); - // value field type in the table should be compatible with Rust's Vec like bytea - builder.value_field("value"); + let mut builder = Mysql::default() + .root("/") + .connection_string("mysql://you_username:your_password@127.0.0.1:5432/your_database") + .table("your_table") + // key field type in the table should be compatible with Rust's &str like text + .key_field("key") + // value field type in the table should be compatible with Rust's Vec like bytea + .value_field("value"); let op = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/obs/backend.rs b/core/src/services/obs/backend.rs index 161549f5601..306ed1734e3 100644 --- a/core/src/services/obs/backend.rs +++ b/core/src/services/obs/backend.rs @@ -95,7 +95,7 @@ impl ObsBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -111,7 +111,7 @@ impl ObsBuilder { /// - `https://obs.cn-north-4.myhuaweicloud.com` /// - `obs.cn-north-4.myhuaweicloud.com` (https by default) /// - `https://custom.obs.com` (port should not be set) - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()); } @@ -122,7 +122,7 @@ impl ObsBuilder { /// Set access_key_id of this backend. /// - If it is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn access_key_id(&mut self, access_key_id: &str) -> &mut Self { + pub fn access_key_id(mut self, access_key_id: &str) -> Self { if !access_key_id.is_empty() { self.config.access_key_id = Some(access_key_id.to_string()); } @@ -133,7 +133,7 @@ impl ObsBuilder { /// Set secret_access_key of this backend. /// - If it is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn secret_access_key(&mut self, secret_access_key: &str) -> &mut Self { + pub fn secret_access_key(mut self, secret_access_key: &str) -> Self { if !secret_access_key.is_empty() { self.config.secret_access_key = Some(secret_access_key.to_string()); } @@ -143,7 +143,7 @@ impl ObsBuilder { /// Set bucket of this backend. /// The param is required. - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { if !bucket.is_empty() { self.config.bucket = Some(bucket.to_string()); } @@ -157,7 +157,7 @@ impl ObsBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/obs/docs.md b/core/src/services/obs/docs.md index d5a928f7f02..9c961055adf 100644 --- a/core/src/services/obs/docs.md +++ b/core/src/services/obs/docs.md @@ -35,18 +35,17 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Obs::default(); - - // set the storage bucket for OpenDAL - builder.bucket("test"); - builder.endpoint("obs.cn-north-1.myhuaweicloud.com"); - // Set the access_key_id and secret_access_key. - // - // OpenDAL will try load credential from the env. - // If credential not set and no valid credential in env, OpenDAL will - // send request without signing like anonymous user. - builder.access_key_id("access_key_id"); - builder.secret_access_key("secret_access_key"); + let mut builder = Obs::default() + // set the storage bucket for OpenDAL + .bucket("test") + .endpoint("obs.cn-north-1.myhuaweicloud.com") + // Set the access_key_id and secret_access_key. + // + // OpenDAL will try load credential from the env. + // If credential not set and no valid credential in env, OpenDAL will + // send request without signing like anonymous user. + .access_key_id("access_key_id") + .secret_access_key("secret_access_key"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/onedrive/builder.rs b/core/src/services/onedrive/builder.rs index fff2126667e..d2bf3f2534c 100644 --- a/core/src/services/onedrive/builder.rs +++ b/core/src/services/onedrive/builder.rs @@ -77,13 +77,13 @@ impl OnedriveBuilder { /// set the bearer access token for OneDrive /// /// default: no access token, which leads to failure - pub fn access_token(&mut self, access_token: &str) -> &mut Self { + pub fn access_token(mut self, access_token: &str) -> Self { self.config.access_token = Some(access_token.to_string()); self } /// Set root path of OneDrive folder. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = Some(root.to_string()); self } @@ -94,7 +94,7 @@ impl OnedriveBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, http_client: HttpClient) -> &mut Self { + pub fn http_client(mut self, http_client: HttpClient) -> Self { self.http_client = Some(http_client); self } diff --git a/core/src/services/onedrive/docs.md b/core/src/services/onedrive/docs.md index e5e1393d196..f4a0f8992a3 100644 --- a/core/src/services/onedrive/docs.md +++ b/core/src/services/onedrive/docs.md @@ -33,9 +33,9 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Onedrive::default(); - - builder.access_token("xxx").root("/path/to/root"); + let mut builder = Onedrive::default() + .access_token("xxx") + .root("/path/to/root"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs index 3eb5e886663..a3563bc1ddc 100644 --- a/core/src/services/oss/backend.rs +++ b/core/src/services/oss/backend.rs @@ -115,7 +115,7 @@ impl OssBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -126,14 +126,14 @@ impl OssBuilder { } /// Set bucket name of this backend. - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { self.config.bucket = bucket.to_string(); self } /// Set endpoint of this backend. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()) @@ -150,7 +150,7 @@ impl OssBuilder { /// /// - If presign_endpoint is set, we will use presign_endpoint on generating presigned urls. /// - if not, we will use endpoint as default. - pub fn presign_endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn presign_endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.presign_endpoint = Some(endpoint.trim_end_matches('/').to_string()) @@ -163,7 +163,7 @@ impl OssBuilder { /// /// - If access_key_id is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn access_key_id(&mut self, v: &str) -> &mut Self { + pub fn access_key_id(mut self, v: &str) -> Self { if !v.is_empty() { self.config.access_key_id = Some(v.to_string()) } @@ -175,7 +175,7 @@ impl OssBuilder { /// /// - If access_key_secret is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn access_key_secret(&mut self, v: &str) -> &mut Self { + pub fn access_key_secret(mut self, v: &str) -> Self { if !v.is_empty() { self.config.access_key_secret = Some(v.to_string()) } @@ -189,7 +189,7 @@ impl OssBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } @@ -253,7 +253,7 @@ impl OssBuilder { /// or not specify the specific CMK ID for OSS-managed KMS key. /// 3. Include the `x-oss-server-side-encryption` parameter in the request and set its value to KMS. /// 4. If a specific CMK ID is specified, include the `x-oss-server-side-encryption-key-id` parameter in the request, and set its value to the specified CMK ID. - pub fn server_side_encryption(&mut self, v: &str) -> &mut Self { + pub fn server_side_encryption(mut self, v: &str) -> Self { if !v.is_empty() { self.config.server_side_encryption = Some(v.to_string()) } @@ -265,7 +265,7 @@ impl OssBuilder { /// # Notes /// /// This option only takes effect when server_side_encryption equals to KMS. - pub fn server_side_encryption_key_id(&mut self, v: &str) -> &mut Self { + pub fn server_side_encryption_key_id(mut self, v: &str) -> Self { if !v.is_empty() { self.config.server_side_encryption_key_id = Some(v.to_string()) } @@ -273,7 +273,7 @@ impl OssBuilder { } /// Set maximum batch operations of this backend. - pub fn batch_max_operations(&mut self, batch_max_operations: usize) -> &mut Self { + pub fn batch_max_operations(mut self, batch_max_operations: usize) -> Self { self.config.batch_max_operations = Some(batch_max_operations); self @@ -281,7 +281,7 @@ impl OssBuilder { /// Allow anonymous will allow opendal to send request without signing /// when credential is not loaded. - pub fn allow_anonymous(&mut self) -> &mut Self { + pub fn allow_anonymous(mut self) -> Self { self.config.allow_anonymous = true; self } diff --git a/core/src/services/oss/docs.md b/core/src/services/oss/docs.md index ae2c74adab3..3a69595e693 100644 --- a/core/src/services/oss/docs.md +++ b/core/src/services/oss/docs.md @@ -44,26 +44,26 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create OSS backend builder. - let mut builder = Oss::default(); - // Set the root for oss, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/path/to/dir"); - // Set the bucket name, this is required. - builder.bucket("test"); - // Set the endpoint. - // - // For example: - // - "https://oss-ap-northeast-1.aliyuncs.com" - // - "https://oss-hangzhou.aliyuncs.com" - builder.endpoint("https://oss-cn-beijing.aliyuncs.com"); - // Set the access_key_id and access_key_secret. - // - // OpenDAL will try load credential from the env. - // If credential not set and no valid credential in env, OpenDAL will - // send request without signing like anonymous user. - builder.access_key_id("access_key_id"); - builder.access_key_secret("access_key_secret"); + let mut builder = Oss::default() + // Set the root for oss, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/path/to/dir") + // Set the bucket name, this is required. + .bucket("test") + // Set the endpoint. + // + // For example: + // - "https://oss-ap-northeast-1.aliyuncs.com" + // - "https://oss-hangzhou.aliyuncs.com" + .endpoint("https://oss-cn-beijing.aliyuncs.com") + // Set the access_key_id and access_key_secret. + // + // OpenDAL will try load credential from the env. + // If credential not set and no valid credential in env, OpenDAL will + // send request without signing like anonymous user. + .access_key_id("access_key_id") + .access_key_secret("access_key_secret"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/pcloud/backend.rs b/core/src/services/pcloud/backend.rs index b355d8fcd59..8afd38e5537 100644 --- a/core/src/services/pcloud/backend.rs +++ b/core/src/services/pcloud/backend.rs @@ -35,7 +35,7 @@ use super::writer::PcloudWriters; use crate::raw::*; use crate::*; -/// Config for backblaze Pcloud services support. +/// Config for Pcloud services support. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -95,7 +95,7 @@ impl PcloudBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -110,7 +110,7 @@ impl PcloudBuilder { /// ref to [doc.pcloud.com](https://docs.pcloud.com/) /// /// It is required. e.g. `https://api.pcloud.com` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = endpoint.to_string(); self @@ -119,7 +119,7 @@ impl PcloudBuilder { /// Pcloud username. /// /// It is required. your pCloud login email, e.g. `example@gmail.com` - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(mut self, username: &str) -> Self { self.config.username = if username.is_empty() { None } else { @@ -132,7 +132,7 @@ impl PcloudBuilder { /// Pcloud password. /// /// It is required. your pCloud login password, e.g. `password` - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { self.config.password = if password.is_empty() { None } else { @@ -148,7 +148,7 @@ impl PcloudBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/pcloud/docs.md b/core/src/services/pcloud/docs.md index ec2bdf02f62..e03c20586a2 100644 --- a/core/src/services/pcloud/docs.md +++ b/core/src/services/pcloud/docs.md @@ -34,16 +34,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Pcloud::default(); - - // set the storage bucket for OpenDAL - builder.root("/"); - // set the bucket for OpenDAL - builder.endpoint("[https](https://api.pcloud.com)"); - // set the username for OpenDAL - builder.username("opendal@gmail.com"); - // set the password name for OpenDAL - builder.password("opendal"); + let mut builder = Pcloud::default() + // set the storage bucket for OpenDAL + .root("/") + // set the bucket for OpenDAL + .endpoint("[https](https://api.pcloud.com)") + // set the username for OpenDAL + .username("opendal@gmail.com") + // set the password name for OpenDAL + .password("opendal"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/persy/backend.rs b/core/src/services/persy/backend.rs index e9c34296693..c285f636e34 100644 --- a/core/src/services/persy/backend.rs +++ b/core/src/services/persy/backend.rs @@ -60,19 +60,19 @@ pub struct PersyBuilder { impl PersyBuilder { /// Set the path to the persy data directory. Will create if not exists. - pub fn datafile(&mut self, path: &str) -> &mut Self { + pub fn datafile(mut self, path: &str) -> Self { self.config.datafile = Some(path.into()); self } /// Set the name of the persy segment. Will create if not exists. - pub fn segment(&mut self, path: &str) -> &mut Self { + pub fn segment(mut self, path: &str) -> Self { self.config.segment = Some(path.into()); self } /// Set the name of the persy index. Will create if not exists. - pub fn index(&mut self, path: &str) -> &mut Self { + pub fn index(mut self, path: &str) -> Self { self.config.index = Some(path.into()); self } diff --git a/core/src/services/persy/docs.md b/core/src/services/persy/docs.md index c5c5b9b5076..97176daca41 100644 --- a/core/src/services/persy/docs.md +++ b/core/src/services/persy/docs.md @@ -32,10 +32,10 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Persy::default(); - builder.datafile("./test.persy"); - builder.segment("data"); - builder.index("index"); + let mut builder = Persy::default() + .datafile("./test.persy") + .segment("data") + .index("index"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/postgresql/backend.rs b/core/src/services/postgresql/backend.rs index 4cd3474851d..2864cb03aed 100644 --- a/core/src/services/postgresql/backend.rs +++ b/core/src/services/postgresql/backend.rs @@ -121,7 +121,7 @@ impl PostgresqlBuilder { /// If connection_string has been specified, other parameters will be ignored. /// /// For more information, please visit - pub fn connection_string(&mut self, v: &str) -> &mut Self { + pub fn connection_string(mut self, v: &str) -> Self { if !v.is_empty() { self.config.connection_string = Some(v.to_string()); } @@ -131,7 +131,7 @@ impl PostgresqlBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } @@ -139,7 +139,7 @@ impl PostgresqlBuilder { } /// Set the table name of the postgresql service to read/write. - pub fn table(&mut self, table: &str) -> &mut Self { + pub fn table(mut self, table: &str) -> Self { if !table.is_empty() { self.config.table = Some(table.to_string()); } @@ -149,7 +149,7 @@ impl PostgresqlBuilder { /// Set the key field name of the postgresql service to read/write. /// /// Default to `key` if not specified. - pub fn key_field(&mut self, key_field: &str) -> &mut Self { + pub fn key_field(mut self, key_field: &str) -> Self { if !key_field.is_empty() { self.config.key_field = Some(key_field.to_string()); } @@ -159,7 +159,7 @@ impl PostgresqlBuilder { /// Set the value field name of the postgresql service to read/write. /// /// Default to `value` if not specified. - pub fn value_field(&mut self, value_field: &str) -> &mut Self { + pub fn value_field(mut self, value_field: &str) -> Self { if !value_field.is_empty() { self.config.value_field = Some(value_field.to_string()); } diff --git a/core/src/services/postgresql/docs.md b/core/src/services/postgresql/docs.md index 95e9ed2b9f2..0c21f2d5538 100644 --- a/core/src/services/postgresql/docs.md +++ b/core/src/services/postgresql/docs.md @@ -32,14 +32,14 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Postgresql::default(); - builder.root("/"); - builder.connection_string("postgresql://you_username:your_password@127.0.0.1:5432/your_database"); - builder.table("your_table"); - // key field type in the table should be compatible with Rust's &str like text - builder.key_field("key"); - // value field type in the table should be compatible with Rust's Vec like bytea - builder.value_field("value"); + let mut builder = Postgresql::default() + .root("/") + .connection_string("postgresql://you_username:your_password@127.0.0.1:5432/your_database") + .table("your_table") + // key field type in the table should be compatible with Rust's &str like text + .key_field("key") + // value field type in the table should be compatible with Rust's Vec like bytea + .value_field("value"); let op = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/redb/backend.rs b/core/src/services/redb/backend.rs index b11b8371bd0..c0c2d551866 100644 --- a/core/src/services/redb/backend.rs +++ b/core/src/services/redb/backend.rs @@ -60,19 +60,19 @@ pub struct RedbBuilder { impl RedbBuilder { /// Set the path to the redb data directory. Will create if not exists. - pub fn datadir(&mut self, path: &str) -> &mut Self { + pub fn datadir(mut self, path: &str) -> Self { self.config.datadir = Some(path.into()); self } /// Set the table name for Redb. - pub fn table(&mut self, table: &str) -> &mut Self { + pub fn table(mut self, table: &str) -> Self { self.config.table = Some(table.into()); self } /// Set the root for Redb. - pub fn root(&mut self, path: &str) -> &mut Self { + pub fn root(mut self, path: &str) -> Self { self.config.root = Some(path.into()); self } diff --git a/core/src/services/redb/docs.md b/core/src/services/redb/docs.md index b13f54f0e35..353b78bf5ba 100644 --- a/core/src/services/redb/docs.md +++ b/core/src/services/redb/docs.md @@ -30,9 +30,9 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Redb::default(); - builder.datadir("/tmp/opendal/redb"); - builder.table("opendal-redb"); + let mut builder = Redb::default() + .datadir("/tmp/opendal/redb") + .table("opendal-redb"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/redis/backend.rs b/core/src/services/redis/backend.rs index 8a31fbe8ef3..c2a62a7c19e 100644 --- a/core/src/services/redis/backend.rs +++ b/core/src/services/redis/backend.rs @@ -128,7 +128,7 @@ impl RedisBuilder { /// - "tcp" or "redis": unsecured redis connections /// - "rediss": secured redis connections /// - "unix" or "redis+unix": unix socket connection - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { self.config.endpoint = Some(endpoint.to_owned()); } @@ -143,7 +143,7 @@ impl RedisBuilder { /// - "tcp" or "redis": unsecured redis connections /// - "rediss": secured redis connections /// - "unix" or "redis+unix": unix socket connection - pub fn cluster_endpoints(&mut self, cluster_endpoints: &str) -> &mut Self { + pub fn cluster_endpoints(mut self, cluster_endpoints: &str) -> Self { if !cluster_endpoints.is_empty() { self.config.cluster_endpoints = Some(cluster_endpoints.to_owned()); } @@ -153,7 +153,7 @@ impl RedisBuilder { /// set the username for redis /// /// default: no username - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(mut self, username: &str) -> Self { if !username.is_empty() { self.config.username = Some(username.to_owned()); } @@ -163,7 +163,7 @@ impl RedisBuilder { /// set the password for redis /// /// default: no password - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { if !password.is_empty() { self.config.password = Some(password.to_owned()); } @@ -173,7 +173,7 @@ impl RedisBuilder { /// set the db used in redis /// /// default: 0 - pub fn db(&mut self, db: i64) -> &mut Self { + pub fn db(mut self, db: i64) -> Self { self.config.db = db; self } @@ -181,7 +181,7 @@ impl RedisBuilder { /// Set the default ttl for redis services. /// /// If set, we will specify `EX` for write operations. - pub fn default_ttl(&mut self, ttl: Duration) -> &mut Self { + pub fn default_ttl(mut self, ttl: Duration) -> Self { self.config.default_ttl = Some(ttl); self } @@ -189,7 +189,7 @@ impl RedisBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } diff --git a/core/src/services/rocksdb/backend.rs b/core/src/services/rocksdb/backend.rs index 93d58c8887c..4d56fd3e947 100644 --- a/core/src/services/rocksdb/backend.rs +++ b/core/src/services/rocksdb/backend.rs @@ -29,10 +29,10 @@ use crate::raw::*; use crate::Result; use crate::*; +/// Config for Rocksdb Service. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] -/// Config for Rocksdb Service. pub struct RocksdbConfig { /// The path to the rocksdb data directory. pub datadir: Option, @@ -57,7 +57,7 @@ pub struct RocksdbBuilder { impl RocksdbBuilder { /// Set the path to the rocksdb data directory. Will create if not exists. - pub fn datadir(&mut self, path: &str) -> &mut Self { + pub fn datadir(mut self, path: &str) -> Self { self.config.datadir = Some(path.into()); self } @@ -65,7 +65,7 @@ impl RocksdbBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } diff --git a/core/src/services/rocksdb/docs.md b/core/src/services/rocksdb/docs.md index 7fa198011ec..9bf02eabf2a 100644 --- a/core/src/services/rocksdb/docs.md +++ b/core/src/services/rocksdb/docs.md @@ -45,8 +45,8 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Rocksdb::default(); - builder.datadir("/tmp/opendal/rocksdb"); + let mut builder = Rocksdb::default() + .datadir("/tmp/opendal/rocksdb"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index a41d9c13907..0feee28a7ea 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -260,7 +260,7 @@ impl S3Builder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -271,7 +271,7 @@ impl S3Builder { } /// Set bucket name of this backend. - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { self.config.bucket = bucket.to_string(); self @@ -289,7 +289,7 @@ impl S3Builder { /// /// If user inputs endpoint without scheme like "s3.amazonaws.com", we /// will prepend "https://" before it. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // Trim trailing `/` so that we can accept `http://127.0.0.1:9000/` self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()) @@ -304,7 +304,7 @@ impl S3Builder { /// If using a custom endpoint, /// - If region is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn region(&mut self, region: &str) -> &mut Self { + pub fn region(mut self, region: &str) -> Self { if !region.is_empty() { self.config.region = Some(region.to_string()) } @@ -316,7 +316,7 @@ impl S3Builder { /// /// - If access_key_id is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn access_key_id(&mut self, v: &str) -> &mut Self { + pub fn access_key_id(mut self, v: &str) -> Self { if !v.is_empty() { self.config.access_key_id = Some(v.to_string()) } @@ -328,7 +328,7 @@ impl S3Builder { /// /// - If secret_access_key is set, we will take user's input first. /// - If not, we will try to load it from environment. - pub fn secret_access_key(&mut self, v: &str) -> &mut Self { + pub fn secret_access_key(mut self, v: &str) -> Self { if !v.is_empty() { self.config.secret_access_key = Some(v.to_string()) } @@ -340,7 +340,7 @@ impl S3Builder { /// /// If `role_arn` is set, we will use already known config as source /// credential to assume role with `role_arn`. - pub fn role_arn(&mut self, v: &str) -> &mut Self { + pub fn role_arn(mut self, v: &str) -> Self { if !v.is_empty() { self.config.role_arn = Some(v.to_string()) } @@ -349,7 +349,7 @@ impl S3Builder { } /// Set external_id for this backend. - pub fn external_id(&mut self, v: &str) -> &mut Self { + pub fn external_id(mut self, v: &str) -> Self { if !v.is_empty() { self.config.external_id = Some(v.to_string()) } @@ -369,7 +369,7 @@ impl S3Builder { /// - `REDUCED_REDUNDANCY` /// - `STANDARD` /// - `STANDARD_IA` - pub fn default_storage_class(&mut self, v: &str) -> &mut Self { + pub fn default_storage_class(mut self, v: &str) -> Self { if !v.is_empty() { self.config.default_storage_class = Some(v.to_string()) } @@ -387,7 +387,7 @@ impl S3Builder { /// /// SSE related options should be set carefully to make them works. /// Please use `server_side_encryption_with_*` helpers if even possible. - pub fn server_side_encryption(&mut self, v: &str) -> &mut Self { + pub fn server_side_encryption(mut self, v: &str) -> Self { if !v.is_empty() { self.config.server_side_encryption = Some(v.to_string()) } @@ -412,7 +412,7 @@ impl S3Builder { /// /// SSE related options should be set carefully to make them works. /// Please use `server_side_encryption_with_*` helpers if even possible. - pub fn server_side_encryption_aws_kms_key_id(&mut self, v: &str) -> &mut Self { + pub fn server_side_encryption_aws_kms_key_id(mut self, v: &str) -> Self { if !v.is_empty() { self.config.server_side_encryption_aws_kms_key_id = Some(v.to_string()) } @@ -430,7 +430,7 @@ impl S3Builder { /// /// SSE related options should be set carefully to make them works. /// Please use `server_side_encryption_with_*` helpers if even possible. - pub fn server_side_encryption_customer_algorithm(&mut self, v: &str) -> &mut Self { + pub fn server_side_encryption_customer_algorithm(mut self, v: &str) -> Self { if !v.is_empty() { self.config.server_side_encryption_customer_algorithm = Some(v.to_string()) } @@ -451,7 +451,7 @@ impl S3Builder { /// /// SSE related options should be set carefully to make them works. /// Please use `server_side_encryption_with_*` helpers if even possible. - pub fn server_side_encryption_customer_key(&mut self, v: &str) -> &mut Self { + pub fn server_side_encryption_customer_key(mut self, v: &str) -> Self { if !v.is_empty() { self.config.server_side_encryption_customer_key = Some(v.to_string()) } @@ -471,7 +471,7 @@ impl S3Builder { /// /// SSE related options should be set carefully to make them works. /// Please use `server_side_encryption_with_*` helpers if even possible. - pub fn server_side_encryption_customer_key_md5(&mut self, v: &str) -> &mut Self { + pub fn server_side_encryption_customer_key_md5(mut self, v: &str) -> Self { if !v.is_empty() { self.config.server_side_encryption_customer_key_md5 = Some(v.to_string()) } @@ -484,7 +484,7 @@ impl S3Builder { /// As known as: SSE-KMS /// /// NOTE: This function should not be used along with other `server_side_encryption_with_` functions. - pub fn server_side_encryption_with_aws_managed_kms_key(&mut self) -> &mut Self { + pub fn server_side_encryption_with_aws_managed_kms_key(mut self) -> Self { self.config.server_side_encryption = Some("aws:kms".to_string()); self } @@ -495,9 +495,9 @@ impl S3Builder { /// /// NOTE: This function should not be used along with other `server_side_encryption_with_` functions. pub fn server_side_encryption_with_customer_managed_kms_key( - &mut self, + mut self, aws_kms_key_id: &str, - ) -> &mut Self { + ) -> Self { self.config.server_side_encryption = Some("aws:kms".to_string()); self.config.server_side_encryption_aws_kms_key_id = Some(aws_kms_key_id.to_string()); self @@ -508,7 +508,7 @@ impl S3Builder { /// As known as: SSE-S3 /// /// NOTE: This function should not be used along with other `server_side_encryption_with_` functions. - pub fn server_side_encryption_with_s3_key(&mut self) -> &mut Self { + pub fn server_side_encryption_with_s3_key(mut self) -> Self { self.config.server_side_encryption = Some("AES256".to_string()); self } @@ -518,11 +518,7 @@ impl S3Builder { /// As known as: SSE-C /// /// NOTE: This function should not be used along with other `server_side_encryption_with_` functions. - pub fn server_side_encryption_with_customer_key( - &mut self, - algorithm: &str, - key: &[u8], - ) -> &mut Self { + pub fn server_side_encryption_with_customer_key(mut self, algorithm: &str, key: &[u8]) -> Self { self.config.server_side_encryption_customer_algorithm = Some(algorithm.to_string()); self.config.server_side_encryption_customer_key = Some(BASE64_STANDARD.encode(key)); self.config.server_side_encryption_customer_key_md5 = @@ -535,7 +531,7 @@ impl S3Builder { /// # Warning /// /// session token's lifetime is short and requires users to refresh in time. - pub fn session_token(&mut self, token: &str) -> &mut Self { + pub fn session_token(mut self, token: &str) -> Self { if !token.is_empty() { self.config.session_token = Some(token.to_string()); } @@ -544,7 +540,7 @@ impl S3Builder { /// Set temporary credential used in AWS S3 connections #[deprecated(note = "Please use `session_token` instead")] - pub fn security_token(&mut self, token: &str) -> &mut Self { + pub fn security_token(self, token: &str) -> Self { self.session_token(token) } @@ -555,7 +551,7 @@ impl S3Builder { /// /// - envs like `AWS_ACCESS_KEY_ID` /// - files like `~/.aws/config` - pub fn disable_config_load(&mut self) -> &mut Self { + pub fn disable_config_load(mut self) -> Self { self.config.disable_config_load = true; self } @@ -564,14 +560,14 @@ impl S3Builder { /// /// This option is used to disable the default behavior of opendal /// to load credential from ec2 metadata, a.k.a, IMDSv2 - pub fn disable_ec2_metadata(&mut self) -> &mut Self { + pub fn disable_ec2_metadata(mut self) -> Self { self.config.disable_ec2_metadata = true; self } /// Allow anonymous will allow opendal to send request without signing /// when credential is not loaded. - pub fn allow_anonymous(&mut self) -> &mut Self { + pub fn allow_anonymous(mut self) -> Self { self.config.allow_anonymous = true; self } @@ -581,7 +577,7 @@ impl S3Builder { /// /// - By default, opendal will send API to `https://s3.us-east-1.amazonaws.com/bucket_name` /// - Enabled, opendal will send API to `https://bucket_name.s3.us-east-1.amazonaws.com` - pub fn enable_virtual_host_style(&mut self) -> &mut Self { + pub fn enable_virtual_host_style(mut self) -> Self { self.config.enable_virtual_host_style = true; self } @@ -589,7 +585,7 @@ impl S3Builder { /// Disable stat with override so that opendal will not send stat request with override queries. /// /// For example, R2 doesn't support stat with `response_content_type` query. - pub fn disable_stat_with_override(&mut self) -> &mut Self { + pub fn disable_stat_with_override(mut self) -> Self { self.config.disable_stat_with_override = true; self } @@ -598,7 +594,7 @@ impl S3Builder { /// /// If customized_credential_load has been set, we will ignore all other /// credential load methods. - pub fn customized_credential_load(&mut self, cred: Box) -> &mut Self { + pub fn customized_credential_load(mut self, cred: Box) -> Self { self.customized_credential_load = Some(cred); self } @@ -609,7 +605,7 @@ impl S3Builder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } @@ -679,7 +675,7 @@ impl S3Builder { } /// Set maximum batch operations of this backend. - pub fn batch_max_operations(&mut self, batch_max_operations: usize) -> &mut Self { + pub fn batch_max_operations(mut self, batch_max_operations: usize) -> Self { self.config.batch_max_operations = Some(batch_max_operations); self @@ -690,7 +686,7 @@ impl S3Builder { /// /// Available options: /// - "crc32c" - pub fn checksum_algorithm(&mut self, checksum_algorithm: &str) -> &mut Self { + pub fn checksum_algorithm(mut self, checksum_algorithm: &str) -> Self { self.config.checksum_algorithm = Some(checksum_algorithm.to_string()); self @@ -1274,9 +1270,9 @@ mod tests { for (bucket, enable_virtual_host_style, expected) in bucket_cases { let mut b = S3Builder::default(); - b.bucket(bucket); + b = b.bucket(bucket); if enable_virtual_host_style { - b.enable_virtual_host_style(); + b = b.enable_virtual_host_style(); } assert_eq!(b.is_bucket_valid(), expected) } @@ -1294,10 +1290,9 @@ mod tests { ]; for endpoint in &endpoint_cases { - let mut b = S3Builder::default(); - b.bucket("test"); + let mut b = S3Builder::default().bucket("test"); if let Some(endpoint) = endpoint { - b.endpoint(endpoint); + b = b.endpoint(endpoint); } let endpoint = b.build_endpoint("us-east-2"); @@ -1305,11 +1300,11 @@ mod tests { } for endpoint in &endpoint_cases { - let mut b = S3Builder::default(); - b.bucket("test"); - b.enable_virtual_host_style(); + let mut b = S3Builder::default() + .bucket("test") + .enable_virtual_host_style(); if let Some(endpoint) = endpoint { - b.endpoint(endpoint); + b = b.endpoint(endpoint); } let endpoint = b.build_endpoint("us-east-2"); diff --git a/core/src/services/s3/docs.md b/core/src/services/s3/docs.md index 0ddc28a15fa..4027f95cac2 100644 --- a/core/src/services/s3/docs.md +++ b/core/src/services/s3/docs.md @@ -86,32 +86,32 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create s3 backend builder. - let mut builder = S3::default(); - // Set the root for s3, all operations will happen under this root. - // - // NOTE: the root must be absolute path. - builder.root("/path/to/dir"); - // Set the bucket name. This is required. - builder.bucket("test"); - // Set the region. This is required for some services, if you don't care about it, for example Minio service, just set it to "auto", it will be ignored. - builder.region("us-east-1"); - // Set the endpoint. - // - // For examples: - // - "https://s3.amazonaws.com" - // - "http://127.0.0.1:9000" - // - "https://oss-ap-northeast-1.aliyuncs.com" - // - "https://cos.ap-seoul.myqcloud.com" - // - // Default to "https://s3.amazonaws.com" - builder.endpoint("https://s3.amazonaws.com"); - // Set the access_key_id and secret_access_key. - // - // OpenDAL will try load credential from the env. - // If credential not set and no valid credential in env, OpenDAL will - // send request without signing like anonymous user. - builder.access_key_id("access_key_id"); - builder.secret_access_key("secret_access_key"); + let mut builder = S3::default() + // Set the root for s3, all operations will happen under this root. + // + // NOTE: the root must be absolute path. + .root("/path/to/dir") + // Set the bucket name. This is required. + .bucket("test") + // Set the region. This is required for some services, if you don't care about it, for example Minio service, just set it to "auto", it will be ignored. + .region("us-east-1") + // Set the endpoint. + // + // For examples: + // - "https://s3.amazonaws.com" + // - "http://127.0.0.1:9000" + // - "https://oss-ap-northeast-1.aliyuncs.com" + // - "https://cos.ap-seoul.myqcloud.com" + // + // Default to "https://s3.amazonaws.com" + .endpoint("https://s3.amazonaws.com") + // Set the access_key_id and secret_access_key. + // + // OpenDAL will try load credential from the env. + // If credential not set and no valid credential in env, OpenDAL will + // send request without signing like anonymous user. + .access_key_id("access_key_id") + .secret_access_key("secret_access_key"); let op: Operator = Operator::new(builder)?.finish(); @@ -130,18 +130,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = S3::default(); - - // Setup builders - builder.root("/path/to/dir"); - builder.bucket("test"); - builder.region("us-east-1"); - builder.endpoint("https://s3.amazonaws.com"); - builder.access_key_id("access_key_id"); - builder.secret_access_key("secret_access_key"); - - // Enable SSE-C - builder.server_side_encryption_with_customer_key("AES256", "customer_key".as_bytes()); + let mut builder = S3::default() + .root("/path/to/dir") + .bucket("test") + .region("us-east-1") + .endpoint("https://s3.amazonaws.com") + .access_key_id("access_key_id") + .secret_access_key("secret_access_key") + // Enable SSE-C + .server_side_encryption_with_customer_key("AES256", "customer_key".as_bytes()); let op = Operator::new(builder)?.finish(); info!("operator: {:?}", op); @@ -162,18 +159,16 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = S3::default(); - - // Setup builders - builder.root("/path/to/dir"); - builder.bucket("test"); - builder.region("us-east-1"); - builder.endpoint("https://s3.amazonaws.com"); - builder.access_key_id("access_key_id"); - builder.secret_access_key("secret_access_key"); - - // Enable SSE-KMS with aws managed kms key - builder.server_side_encryption_with_aws_managed_kms_key(); + let mut builder = S3::default() + // Setup builders + .root("/path/to/dir") + .bucket("test") + .region("us-east-1") + .endpoint("https://s3.amazonaws.com") + .access_key_id("access_key_id") + .secret_access_key("secret_access_key") + // Enable SSE-KMS with aws managed kms key + .server_side_encryption_with_aws_managed_kms_key(); let op = Operator::new(builder)?.finish(); info!("operator: {:?}", op); @@ -194,18 +189,16 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = S3::default(); - - // Setup builders - builder.root("/path/to/dir"); - builder.bucket("test"); - builder.region("us-east-1"); - builder.endpoint("https://s3.amazonaws.com"); - builder.access_key_id("access_key_id"); - builder.secret_access_key("secret_access_key"); - - // Enable SSE-KMS with customer managed kms key - builder.server_side_encryption_with_customer_managed_kms_key("aws_kms_key_id"); + let mut builder = S3::default() + // Setup builders + .root("/path/to/dir") + .bucket("test") + .region("us-east-1") + .endpoint("https://s3.amazonaws.com") + .access_key_id("access_key_id") + .secret_access_key("secret_access_key") + // Enable SSE-KMS with customer managed kms key + .server_side_encryption_with_customer_managed_kms_key("aws_kms_key_id"); let op = Operator::new(builder)?.finish(); info!("operator: {:?}", op); @@ -226,18 +219,16 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = S3::default(); - - // Setup builders - builder.root("/path/to/dir"); - builder.bucket("test"); - builder.region("us-east-1"); - builder.endpoint("https://s3.amazonaws.com"); - builder.access_key_id("access_key_id"); - builder.secret_access_key("secret_access_key"); - - // Enable SSE-S3 - builder.server_side_encryption_with_s3_key(); + let mut builder = S3::default() + // Setup builders + .root("/path/to/dir") + .bucket("test") + .region("us-east-1") + .endpoint("https://s3.amazonaws.com") + .access_key_id("access_key_id") + .secret_access_key("secret_access_key") + // Enable SSE-S3 + .server_side_encryption_with_s3_key(); let op = Operator::new(builder)?.finish(); info!("operator: {:?}", op); diff --git a/core/src/services/seafile/backend.rs b/core/src/services/seafile/backend.rs index 1fa9eedd558..ce214aa0779 100644 --- a/core/src/services/seafile/backend.rs +++ b/core/src/services/seafile/backend.rs @@ -102,7 +102,7 @@ impl SeafileBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -115,7 +115,7 @@ impl SeafileBuilder { /// endpoint of this backend. /// /// It is required. e.g. `http://127.0.0.1:80` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -128,7 +128,7 @@ impl SeafileBuilder { /// username of this backend. /// /// It is required. e.g. `me@example.com` - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(mut self, username: &str) -> Self { self.config.username = if username.is_empty() { None } else { @@ -141,7 +141,7 @@ impl SeafileBuilder { /// password of this backend. /// /// It is required. e.g. `asecret` - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { self.config.password = if password.is_empty() { None } else { @@ -154,7 +154,7 @@ impl SeafileBuilder { /// Set repo name of this backend. /// /// It is required. e.g. `myrepo` - pub fn repo_name(&mut self, repo_name: &str) -> &mut Self { + pub fn repo_name(mut self, repo_name: &str) -> Self { self.config.repo_name = repo_name.to_string(); self @@ -166,7 +166,7 @@ impl SeafileBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/seafile/docs.md b/core/src/services/seafile/docs.md index d7287c802ee..f46ed174d42 100644 --- a/core/src/services/seafile/docs.md +++ b/core/src/services/seafile/docs.md @@ -35,18 +35,17 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Seafile::default(); - - // set the storage bucket for OpenDAL - builder.root("/"); - // set the endpoint for OpenDAL - builder.endpoint("http://127.0.0.1:80"); - // set the username for OpenDAL - builder.username("xxxxxxxxxx"); - // set the password name for OpenDAL - builder.password("opendal"); - // set the repo_name for OpenDAL - builder.repo_name("xxxxxxxxxxxxx"); + let mut builder = Seafile::default() + // set the storage bucket for OpenDAL + .root("/") + // set the endpoint for OpenDAL + .endpoint("http://127.0.0.1:80") + // set the username for OpenDAL + .username("xxxxxxxxxx") + // set the password name for OpenDAL + .password("opendal") + // set the repo_name for OpenDAL + .repo_name("xxxxxxxxxxxxx"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/sftp/backend.rs b/core/src/services/sftp/backend.rs index 9fc1a6666c1..0a6b95dc11d 100644 --- a/core/src/services/sftp/backend.rs +++ b/core/src/services/sftp/backend.rs @@ -104,7 +104,7 @@ impl Debug for SftpBuilder { impl SftpBuilder { /// set endpoint for sftp backend. /// The format is same as `openssh`, using either `[user@]hostname` or `ssh://[user@]hostname[:port]`. A username or port that is specified in the endpoint overrides the one set in the builder (but does not change the builder). - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -116,7 +116,7 @@ impl SftpBuilder { /// set root path for sftp backend. /// It uses the default directory set by the remote `sftp-server` as default. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -127,7 +127,7 @@ impl SftpBuilder { } /// set user for sftp backend. - pub fn user(&mut self, user: &str) -> &mut Self { + pub fn user(mut self, user: &str) -> Self { self.config.user = if user.is_empty() { None } else { @@ -138,7 +138,7 @@ impl SftpBuilder { } /// set key path for sftp backend. - pub fn key(&mut self, key: &str) -> &mut Self { + pub fn key(mut self, key: &str) -> Self { self.config.key = if key.is_empty() { None } else { @@ -153,7 +153,7 @@ impl SftpBuilder { /// - Strict (default) /// - Accept /// - Add - pub fn known_hosts_strategy(&mut self, strategy: &str) -> &mut Self { + pub fn known_hosts_strategy(mut self, strategy: &str) -> Self { self.config.known_hosts_strategy = if strategy.is_empty() { None } else { @@ -165,7 +165,7 @@ impl SftpBuilder { /// set enable_copy for sftp backend. /// It requires the server supports copy-file extension. - pub fn enable_copy(&mut self, enable_copy: bool) -> &mut Self { + pub fn enable_copy(mut self, enable_copy: bool) -> Self { self.config.enable_copy = enable_copy; self diff --git a/core/src/services/sftp/docs.md b/core/src/services/sftp/docs.md index 9548e008a41..43b08c74850 100644 --- a/core/src/services/sftp/docs.md +++ b/core/src/services/sftp/docs.md @@ -38,9 +38,10 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Sftp::default(); - - builder.endpoint("127.0.0.1").user("test").key("test_key"); + let mut builder = Sftp::default() + .endpoint("127.0.0.1") + .user("test") + .key("test_key"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/sled/backend.rs b/core/src/services/sled/backend.rs index e7d14efddbe..23b1e80f6a5 100644 --- a/core/src/services/sled/backend.rs +++ b/core/src/services/sled/backend.rs @@ -80,19 +80,19 @@ impl Debug for SledBuilder { impl SledBuilder { /// Set the path to the sled data directory. Will create if not exists. - pub fn datadir(&mut self, path: &str) -> &mut Self { + pub fn datadir(mut self, path: &str) -> Self { self.config.datadir = Some(path.into()); self } /// Set the root for sled. - pub fn root(&mut self, path: &str) -> &mut Self { + pub fn root(mut self, path: &str) -> Self { self.config.root = Some(path.into()); self } /// Set the tree for sled. - pub fn tree(&mut self, tree: &str) -> &mut Self { + pub fn tree(mut self, tree: &str) -> Self { self.config.tree = Some(tree.into()); self } diff --git a/core/src/services/sled/docs.md b/core/src/services/sled/docs.md index 091a4a14bdb..69dd96106a1 100644 --- a/core/src/services/sled/docs.md +++ b/core/src/services/sled/docs.md @@ -30,8 +30,8 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Sled::default(); - builder.datadir("/tmp/opendal/sled"); + let mut builder = Sled::default() + .datadir("/tmp/opendal/sled"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/sqlite/backend.rs b/core/src/services/sqlite/backend.rs index 963bb6f694a..f4878e71654 100644 --- a/core/src/services/sqlite/backend.rs +++ b/core/src/services/sqlite/backend.rs @@ -109,7 +109,7 @@ impl SqliteBuilder { /// - `file://data.db` /// /// For more information, please refer to [Opening A New Database Connection](http://www.sqlite.org/c3ref/open.html) - pub fn connection_string(&mut self, v: &str) -> &mut Self { + pub fn connection_string(mut self, v: &str) -> Self { if !v.is_empty() { self.config.connection_string = Some(v.to_string()); } @@ -119,7 +119,7 @@ impl SqliteBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_owned()); } @@ -127,7 +127,7 @@ impl SqliteBuilder { } /// Set the table name of the sqlite service to read/write. - pub fn table(&mut self, table: &str) -> &mut Self { + pub fn table(mut self, table: &str) -> Self { if !table.is_empty() { self.config.table = Some(table.to_string()); } @@ -137,7 +137,7 @@ impl SqliteBuilder { /// Set the key field name of the sqlite service to read/write. /// /// Default to `key` if not specified. - pub fn key_field(&mut self, key_field: &str) -> &mut Self { + pub fn key_field(mut self, key_field: &str) -> Self { if !key_field.is_empty() { self.config.key_field = Some(key_field.to_string()); } @@ -147,7 +147,7 @@ impl SqliteBuilder { /// Set the value field name of the sqlite service to read/write. /// /// Default to `value` if not specified. - pub fn value_field(&mut self, value_field: &str) -> &mut Self { + pub fn value_field(mut self, value_field: &str) -> Self { if !value_field.is_empty() { self.config.value_field = Some(value_field.to_string()); } diff --git a/core/src/services/sqlite/docs.md b/core/src/services/sqlite/docs.md index 0d1ad2a78b0..b7562e21abf 100644 --- a/core/src/services/sqlite/docs.md +++ b/core/src/services/sqlite/docs.md @@ -31,14 +31,14 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Sqlite::default(); - builder.root("/"); - builder.connection_string("file//abc.db"); - builder.table("your_table"); - // key field type in the table should be compatible with Rust's &str like text - builder.key_field("key"); - // value field type in the table should be compatible with Rust's Vec like bytea - builder.value_field("value"); + let mut builder = Sqlite::default() + .root("/") + .connection_string("file//abc.db") + .table("your_table") + // key field type in the table should be compatible with Rust's &str like text + .key_field("key") + // value field type in the table should be compatible with Rust's Vec like bytea + .value_field("value"); let op = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/supabase/backend.rs b/core/src/services/supabase/backend.rs index 266d75ef7c4..cd8e89cc5ee 100644 --- a/core/src/services/supabase/backend.rs +++ b/core/src/services/supabase/backend.rs @@ -84,7 +84,7 @@ impl SupabaseBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -95,7 +95,7 @@ impl SupabaseBuilder { } /// Set bucket name of this backend. - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { self.config.bucket = bucket.to_string(); self } @@ -103,7 +103,7 @@ impl SupabaseBuilder { /// Set endpoint of this backend. /// /// Endpoint must be full uri - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -115,7 +115,7 @@ impl SupabaseBuilder { /// Set the authorization key for this backend /// Do not set this key if you want to read public bucket - pub fn key(&mut self, key: &str) -> &mut Self { + pub fn key(mut self, key: &str) -> Self { self.config.key = Some(key.to_string()); self } @@ -126,7 +126,7 @@ impl SupabaseBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/supabase/docs.md b/core/src/services/supabase/docs.md index 9c976bd7ef7..629d28a77e4 100644 --- a/core/src/services/supabase/docs.md +++ b/core/src/services/supabase/docs.md @@ -35,13 +35,12 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Supabase::default(); - - builder.root("/"); - builder.bucket("test_bucket"); - builder.endpoint("http://127.0.0.1:54321"); - // this sets up the anon_key, which means this operator can only write public resource - builder.key("some_anon_key"); + let mut builder = Supabase::default() + .root("/") + .bucket("test_bucket") + .endpoint("http://127.0.0.1:54321") + // this sets up the anon_key, which means this operator can only write public resource + .key("some_anon_key"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/surrealdb/backend.rs b/core/src/services/surrealdb/backend.rs index 509ca778b01..64c4d5a1c33 100644 --- a/core/src/services/surrealdb/backend.rs +++ b/core/src/services/surrealdb/backend.rs @@ -104,7 +104,7 @@ impl SurrealdbBuilder { /// - `wss://ip:port` /// - `http://ip:port` /// - `https://ip:port` - pub fn connection_string(&mut self, connection_string: &str) -> &mut Self { + pub fn connection_string(mut self, connection_string: &str) -> Self { if !connection_string.is_empty() { self.config.connection_string = Some(connection_string.to_string()); } @@ -114,7 +114,7 @@ impl SurrealdbBuilder { /// set the working directory, all operations will be performed under it. /// /// default: "/" - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()); } @@ -122,7 +122,7 @@ impl SurrealdbBuilder { } /// Set the table name of the surrealdb service for read/write. - pub fn table(&mut self, table: &str) -> &mut Self { + pub fn table(mut self, table: &str) -> Self { if !table.is_empty() { self.config.table = Some(table.to_string()); } @@ -130,7 +130,7 @@ impl SurrealdbBuilder { } /// Set the username of the surrealdb service for signin. - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(mut self, username: &str) -> Self { if !username.is_empty() { self.config.username = Some(username.to_string()); } @@ -138,7 +138,7 @@ impl SurrealdbBuilder { } /// Set the password of the surrealdb service for signin. - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { if !password.is_empty() { self.config.password = Some(password.to_string()); } @@ -146,7 +146,7 @@ impl SurrealdbBuilder { } /// Set the namespace of the surrealdb service for read/write. - pub fn namespace(&mut self, namespace: &str) -> &mut Self { + pub fn namespace(mut self, namespace: &str) -> Self { if !namespace.is_empty() { self.config.namespace = Some(namespace.to_string()); } @@ -154,7 +154,7 @@ impl SurrealdbBuilder { } /// Set the database of the surrealdb service for read/write. - pub fn database(&mut self, database: &str) -> &mut Self { + pub fn database(mut self, database: &str) -> Self { if !database.is_empty() { self.config.database = Some(database.to_string()); } @@ -164,7 +164,7 @@ impl SurrealdbBuilder { /// Set the key field name of the surrealdb service for read/write. /// /// Default to `key` if not specified. - pub fn key_field(&mut self, key_field: &str) -> &mut Self { + pub fn key_field(mut self, key_field: &str) -> Self { if !key_field.is_empty() { self.config.key_field = Some(key_field.to_string()); } @@ -174,7 +174,7 @@ impl SurrealdbBuilder { /// Set the value field name of the surrealdb service for read/write. /// /// Default to `value` if not specified. - pub fn value_field(&mut self, value_field: &str) -> &mut Self { + pub fn value_field(mut self, value_field: &str) -> Self { if !value_field.is_empty() { self.config.value_field = Some(value_field.to_string()); } diff --git a/core/src/services/surrealdb/docs.md b/core/src/services/surrealdb/docs.md index de22c5211c2..52e04df123b 100644 --- a/core/src/services/surrealdb/docs.md +++ b/core/src/services/surrealdb/docs.md @@ -37,16 +37,16 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Surrealdb::default(); - builder.root("/"); - builder.connection_string("ws://127.0.0.1:8000"); - builder.username("username"); - builder.password("password"); - builder.namespace("namespace"); - builder.database("database"); - builder.table("table"); - builder.key_field("key"); - builder.value_field("value"); + let mut builder = Surrealdb::default() + .root("/") + .connection_string("ws://127.0.0.1:8000") + .username("username") + .password("password") + .namespace("namespace") + .database("database") + .table("table") + .key_field("key") + .value_field("value"); let op = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/swift/backend.rs b/core/src/services/swift/backend.rs index a10fea9e1a7..ef94c95d9db 100644 --- a/core/src/services/swift/backend.rs +++ b/core/src/services/swift/backend.rs @@ -97,7 +97,7 @@ impl SwiftBuilder { /// /// If user inputs endpoint without scheme, we will /// prepend `https://` to it. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -109,7 +109,7 @@ impl SwiftBuilder { /// Set container of this backend. /// /// All operations will happen under this container. It is required. e.g. `snapshots` - pub fn container(&mut self, container: &str) -> &mut Self { + pub fn container(mut self, container: &str) -> Self { self.config.container = if container.is_empty() { None } else { @@ -121,7 +121,7 @@ impl SwiftBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -132,7 +132,7 @@ impl SwiftBuilder { /// Set the token of this backend. /// /// Default to empty string. - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { self.config.token = Some(token.to_string()); } diff --git a/core/src/services/swift/docs.md b/core/src/services/swift/docs.md index 88bd2128351..00bb5513ad8 100644 --- a/core/src/services/swift/docs.md +++ b/core/src/services/swift/docs.md @@ -35,16 +35,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // Create Swift backend builder - let mut builder = Swift::default(); - - // Set the root for swift, all operations will happen under this root - builder.root("/path/to/dir"); - // set the endpoint of Swift backend - builder.endpoint("https://openstack-controller.example.com:8080/v1/account"); - // set the container name of Swift workspace - builder.container("container"); - // set the auth token for builder - builder.token("token"); + let mut builder = Swift::default() + // Set the root for swift, all operations will happen under this root + .root("/path/to/dir") + // set the endpoint of Swift backend + .endpoint("https://openstack-controller.example.com:8080/v1/account") + // set the container name of Swift workspace + .container("container") + // set the auth token for builder + .token("token"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/tikv/backend.rs b/core/src/services/tikv/backend.rs index a85eb4495e7..49b80bee268 100644 --- a/core/src/services/tikv/backend.rs +++ b/core/src/services/tikv/backend.rs @@ -87,7 +87,7 @@ impl Debug for TikvBuilder { impl TikvBuilder { /// Set the network address of the TiKV service. - pub fn endpoints(&mut self, endpoints: Vec) -> &mut Self { + pub fn endpoints(mut self, endpoints: Vec) -> Self { if !endpoints.is_empty() { self.config.endpoints = Some(endpoints) } @@ -95,13 +95,13 @@ impl TikvBuilder { } /// Set the insecure connection to TiKV. - pub fn insecure(&mut self) -> &mut Self { + pub fn insecure(mut self) -> Self { self.config.insecure = true; self } /// Set the certificate authority file path. - pub fn ca_path(&mut self, ca_path: &str) -> &mut Self { + pub fn ca_path(mut self, ca_path: &str) -> Self { if !ca_path.is_empty() { self.config.ca_path = Some(ca_path.to_string()) } @@ -109,7 +109,7 @@ impl TikvBuilder { } /// Set the certificate file path. - pub fn cert_path(&mut self, cert_path: &str) -> &mut Self { + pub fn cert_path(mut self, cert_path: &str) -> Self { if !cert_path.is_empty() { self.config.cert_path = Some(cert_path.to_string()) } @@ -117,7 +117,7 @@ impl TikvBuilder { } /// Set the key file path. - pub fn key_path(&mut self, key_path: &str) -> &mut Self { + pub fn key_path(mut self, key_path: &str) -> Self { if !key_path.is_empty() { self.config.key_path = Some(key_path.to_string()) } diff --git a/core/src/services/tikv/docs.md b/core/src/services/tikv/docs.md index 642374892c9..abccf800dca 100644 --- a/core/src/services/tikv/docs.md +++ b/core/src/services/tikv/docs.md @@ -34,8 +34,8 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Tikv::default(); - builder.endpoints(vec!["127.0.0.1:2379".to_string()]); + let mut builder = Tikv::default() + .endpoints(vec!["127.0.0.1:2379".to_string()]); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/upyun/backend.rs b/core/src/services/upyun/backend.rs index 16c0daab3b1..67cb9000032 100644 --- a/core/src/services/upyun/backend.rs +++ b/core/src/services/upyun/backend.rs @@ -33,7 +33,7 @@ use super::writer::UpyunWriters; use crate::raw::*; use crate::*; -/// Config for backblaze upyun services support. +/// Config for upyun services support. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -93,7 +93,7 @@ impl UpyunBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -106,7 +106,7 @@ impl UpyunBuilder { /// bucket of this backend. /// /// It is required. e.g. `test` - pub fn bucket(&mut self, bucket: &str) -> &mut Self { + pub fn bucket(mut self, bucket: &str) -> Self { self.config.bucket = bucket.to_string(); self @@ -115,7 +115,7 @@ impl UpyunBuilder { /// operator of this backend. /// /// It is required. e.g. `test` - pub fn operator(&mut self, operator: &str) -> &mut Self { + pub fn operator(mut self, operator: &str) -> Self { self.config.operator = if operator.is_empty() { None } else { @@ -128,7 +128,7 @@ impl UpyunBuilder { /// password of this backend. /// /// It is required. e.g. `asecret` - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { self.config.password = if password.is_empty() { None } else { @@ -144,7 +144,7 @@ impl UpyunBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/upyun/docs.md b/core/src/services/upyun/docs.md index be3cff5e1c8..2e454ed9235 100644 --- a/core/src/services/upyun/docs.md +++ b/core/src/services/upyun/docs.md @@ -34,16 +34,15 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Upyun::default(); - - // set the storage bucket for OpenDAL - builder.root("/"); - // set the bucket for OpenDAL - builder.bucket("test"); - // set the operator for OpenDAL - builder.operator("xxxxxxxxxx"); - // set the password name for OpenDAL - builder.password("opendal"); + let mut builder = Upyun::default() + // set the storage bucket for OpenDAL + .root("/") + // set the bucket for OpenDAL + .bucket("test") + // set the operator for OpenDAL + .operator("xxxxxxxxxx") + // set the password name for OpenDAL + .password("opendal"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/vercel_artifacts/builder.rs b/core/src/services/vercel_artifacts/builder.rs index b7f8d253a94..ee41e29e888 100644 --- a/core/src/services/vercel_artifacts/builder.rs +++ b/core/src/services/vercel_artifacts/builder.rs @@ -73,7 +73,7 @@ impl VercelArtifactsBuilder { /// set the bearer access token for Vercel /// /// default: no access token, which leads to failure - pub fn access_token(&mut self, access_token: &str) -> &mut Self { + pub fn access_token(mut self, access_token: &str) -> Self { self.config.access_token = Some(access_token.to_string()); self } @@ -84,7 +84,7 @@ impl VercelArtifactsBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, http_client: HttpClient) -> &mut Self { + pub fn http_client(mut self, http_client: HttpClient) -> Self { self.http_client = Some(http_client); self } diff --git a/core/src/services/vercel_artifacts/docs.md b/core/src/services/vercel_artifacts/docs.md index 234429fd05d..adbc250bfcf 100644 --- a/core/src/services/vercel_artifacts/docs.md +++ b/core/src/services/vercel_artifacts/docs.md @@ -31,9 +31,8 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = VercelArtifacts::default(); - - builder.access_token("xxx"); + let mut builder = VercelArtifacts::default() + .access_token("xxx"); let op: Operator = Operator::new(builder)?.finish(); Ok(()) diff --git a/core/src/services/vercel_blob/backend.rs b/core/src/services/vercel_blob/backend.rs index 9e94ab1cc9a..256ef35898a 100644 --- a/core/src/services/vercel_blob/backend.rs +++ b/core/src/services/vercel_blob/backend.rs @@ -36,7 +36,7 @@ use super::writer::VercelBlobWriters; use crate::raw::*; use crate::*; -/// Config for backblaze VercelBlob services support. +/// Config for VercelBlob services support. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -90,7 +90,7 @@ impl VercelBlobBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -104,7 +104,7 @@ impl VercelBlobBuilder { /// /// Get from Vercel environment variable `BLOB_READ_WRITE_TOKEN`. /// It is required. - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { self.config.token = token.to_string(); self @@ -116,7 +116,7 @@ impl VercelBlobBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/vercel_blob/docs.md b/core/src/services/vercel_blob/docs.md index 8cc8eed53db..39a227192ff 100644 --- a/core/src/services/vercel_blob/docs.md +++ b/core/src/services/vercel_blob/docs.md @@ -32,12 +32,11 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = VercelBlob::default(); - - // set the storage bucket for OpenDAL - builder.root("/"); - // set the token for OpenDAL - builder.token("you_token"); + let mut builder = VercelBlob::default() + // set the storage bucket for OpenDAL + .root("/") + // set the token for OpenDAL + .token("you_token"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/webdav/backend.rs b/core/src/services/webdav/backend.rs index 68b06f541ca..19212ca0544 100644 --- a/core/src/services/webdav/backend.rs +++ b/core/src/services/webdav/backend.rs @@ -95,7 +95,7 @@ impl WebdavBuilder { /// Set endpoint for http backend. /// /// For example: `https://example.com` - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { self.config.endpoint = if endpoint.is_empty() { None } else { @@ -108,7 +108,7 @@ impl WebdavBuilder { /// set the username for Webdav /// /// default: no username - pub fn username(&mut self, username: &str) -> &mut Self { + pub fn username(mut self, username: &str) -> Self { if !username.is_empty() { self.config.username = Some(username.to_owned()); } @@ -118,7 +118,7 @@ impl WebdavBuilder { /// set the password for Webdav /// /// default: no password - pub fn password(&mut self, password: &str) -> &mut Self { + pub fn password(mut self, password: &str) -> Self { if !password.is_empty() { self.config.password = Some(password.to_owned()); } @@ -128,7 +128,7 @@ impl WebdavBuilder { /// set the bearer token for Webdav /// /// default: no access token - pub fn token(&mut self, token: &str) -> &mut Self { + pub fn token(mut self, token: &str) -> Self { if !token.is_empty() { self.config.token = Some(token.to_owned()); } @@ -136,7 +136,7 @@ impl WebdavBuilder { } /// Set root path of http backend. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -152,7 +152,7 @@ impl WebdavBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/webdav/docs.md b/core/src/services/webdav/docs.md index 08e491fd042..c09b23299a3 100644 --- a/core/src/services/webdav/docs.md +++ b/core/src/services/webdav/docs.md @@ -37,11 +37,10 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = Webdav::default(); - - builder.endpoint("127.0.0.1"); - builder.username("xxx"); - builder.password("xxx"); + let mut builder = Webdav::default() + .endpoint("127.0.0.1") + .username("xxx") + .password("xxx"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/webhdfs/backend.rs b/core/src/services/webhdfs/backend.rs index e5cea6a1915..7becff23669 100644 --- a/core/src/services/webhdfs/backend.rs +++ b/core/src/services/webhdfs/backend.rs @@ -98,7 +98,7 @@ impl WebhdfsBuilder { /// # Note /// /// The root will be automatically created if not exists. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { if !root.is_empty() { self.config.root = Some(root.to_string()) } @@ -116,7 +116,7 @@ impl WebhdfsBuilder { /// /// If user inputs endpoint without scheme, we will /// prepend `http://` to it. - pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { + pub fn endpoint(mut self, endpoint: &str) -> Self { if !endpoint.is_empty() { // trim tailing slash so we can accept `http://127.0.0.1:9870/` self.config.endpoint = Some(endpoint.trim_end_matches('/').to_string()); @@ -130,7 +130,7 @@ impl WebhdfsBuilder { /// # Note /// The builder prefers using delegation token over username. /// If both are set, delegation token will be used. - pub fn delegation(&mut self, delegation: &str) -> &mut Self { + pub fn delegation(mut self, delegation: &str) -> Self { if !delegation.is_empty() { self.config.delegation = Some(delegation.to_string()); } @@ -143,7 +143,7 @@ impl WebhdfsBuilder { /// /// When listing a directory, the backend will default to use batch listing. /// If disabled, the backend will list all files/directories in one request. - pub fn disable_list_batch(&mut self) -> &mut Self { + pub fn disable_list_batch(mut self) -> Self { self.config.disable_list_batch = true; self } @@ -153,7 +153,7 @@ impl WebhdfsBuilder { /// # Notes /// /// If not set, write multi not support, eg: `.opendal_tmp/`. - pub fn atomic_write_dir(&mut self, dir: &str) -> &mut Self { + pub fn atomic_write_dir(mut self, dir: &str) -> Self { self.config.atomic_write_dir = if dir.is_empty() { None } else { diff --git a/core/src/services/webhdfs/docs.md b/core/src/services/webhdfs/docs.md index cf3be4ebd2e..6dce0b6e660 100644 --- a/core/src/services/webhdfs/docs.md +++ b/core/src/services/webhdfs/docs.md @@ -66,22 +66,22 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { - let mut builder = Webhdfs::default(); - // set the root for WebHDFS, all operations will happen under this root - // - // Note: - // if the root is not exists, the builder will automatically create the - // root directory for you - // if the root exists and is a directory, the builder will continue working - // if the root exists and is a folder, the builder will fail on building backend - builder.root("/path/to/dir"); - // set the endpoint of webhdfs namenode, controlled by dfs.namenode.http-address - // default is http://127.0.0.1:9870 - builder.endpoint("http://127.0.0.1:9870"); - // set the delegation_token for builder - builder.delegation("delegation_token"); - // set atomic_write_dir for builder - builder.atomic_write_dir(".opendal_tmp/"); + let mut builder = Webhdfs::default() + // set the root for WebHDFS, all operations will happen under this root + // + // Note: + // if the root is not exists, the builder will automatically create the + // root directory for you + // if the root exists and is a directory, the builder will continue working + // if the root exists and is a folder, the builder will fail on building backend + .root("/path/to/dir") + // set the endpoint of webhdfs namenode, controlled by dfs.namenode.http-address + // default is http://127.0.0.1:9870 + .endpoint("http://127.0.0.1:9870") + // set the delegation_token for builder + .delegation("delegation_token") + // set atomic_write_dir for builder + .atomic_write_dir(".opendal_tmp/"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/services/yandex_disk/backend.rs b/core/src/services/yandex_disk/backend.rs index af5a4bc4eec..dfc767264f5 100644 --- a/core/src/services/yandex_disk/backend.rs +++ b/core/src/services/yandex_disk/backend.rs @@ -36,7 +36,7 @@ use super::writer::YandexDiskWriters; use crate::raw::*; use crate::*; -/// Config for backblaze YandexDisk services support. +/// Config for YandexDisk services support. #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(default)] #[non_exhaustive] @@ -90,7 +90,7 @@ impl YandexDiskBuilder { /// Set root of this backend. /// /// All operations will happen under this root. - pub fn root(&mut self, root: &str) -> &mut Self { + pub fn root(mut self, root: &str) -> Self { self.config.root = if root.is_empty() { None } else { @@ -104,7 +104,7 @@ impl YandexDiskBuilder { /// The valid token will looks like `y0_XXXXXXqihqIWAADLWwAAAAD3IXXXXXX0gtVeSPeIKM0oITMGhXXXXXX`. /// We can fetch the debug token from . /// To use it in production, please register an app at instead. - pub fn access_token(&mut self, access_token: &str) -> &mut Self { + pub fn access_token(mut self, access_token: &str) -> Self { self.config.access_token = access_token.to_string(); self @@ -116,7 +116,7 @@ impl YandexDiskBuilder { /// /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed /// during minor updates. - pub fn http_client(&mut self, client: HttpClient) -> &mut Self { + pub fn http_client(mut self, client: HttpClient) -> Self { self.http_client = Some(client); self } diff --git a/core/src/services/yandex_disk/docs.md b/core/src/services/yandex_disk/docs.md index 988df264a00..d420fe371da 100644 --- a/core/src/services/yandex_disk/docs.md +++ b/core/src/services/yandex_disk/docs.md @@ -32,12 +32,11 @@ use opendal::Operator; #[tokio::main] async fn main() -> Result<()> { // create backend builder - let mut builder = YandexDisk::default(); - - // set the storage bucket for OpenDAL - builder.root("/"); - // set the access_token for OpenDAL - builder.access_token("test"); + let mut builder = YandexDisk::default() + // set the storage bucket for OpenDAL + .root("/") + // set the access_token for OpenDAL + .access_token("test"); let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/types/builder.rs b/core/src/types/builder.rs index dac7b23efd0..8fbd8d8644f 100644 --- a/core/src/types/builder.rs +++ b/core/src/types/builder.rs @@ -38,11 +38,7 @@ use crate::*; /// use opendal::Operator; /// async fn test() -> Result<()> { /// // Create fs backend builder. -/// let mut builder = Fs::default(); -/// // Set the root for fs, all operations will happen under this root. -/// // -/// // NOTE: the root must be absolute path. -/// builder.root("/tmp"); +/// let mut builder = Fs::default().root("/tmp"); /// /// // Build an `Operator` to start operating the storage. /// let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/types/list.rs b/core/src/types/list.rs index fe70b00e7cb..8b3bb341b4f 100644 --- a/core/src/types/list.rs +++ b/core/src/types/list.rs @@ -298,9 +298,7 @@ mod tests { async fn test_invalid_lister() -> Result<()> { let _ = tracing_subscriber::fmt().try_init(); - let mut builder = Azblob::default(); - - builder + let builder = Azblob::default() .container("container") .account_name("account_name") .account_key("account_key") diff --git a/core/src/types/operator/blocking_operator.rs b/core/src/types/operator/blocking_operator.rs index f2b6422c134..5879d22daf4 100644 --- a/core/src/types/operator/blocking_operator.rs +++ b/core/src/types/operator/blocking_operator.rs @@ -37,11 +37,7 @@ use crate::*; /// /// fn main() -> Result<()> { /// // Create fs backend builder. -/// let mut builder = Fs::default(); -/// // Set the root for fs, all operations will happen under this root. -/// // -/// // NOTE: the root must be absolute path. -/// builder.root("/tmp"); +/// let builder = Fs::default().root("/tmp"); /// /// // Build an `BlockingOperator` to start operating the storage. /// let _: BlockingOperator = Operator::new(builder)?.finish().blocking(); @@ -64,9 +60,7 @@ use crate::*; /// /// async fn test() -> Result<()> { /// // Create fs backend builder. -/// let mut builder = S3::default(); -/// builder.bucket("test"); -/// builder.region("us-east-1"); +/// let mut builder = S3::default().bucket("test").region("us-east-1"); /// /// // Build an `BlockingOperator` with blocking layer to start operating the storage. /// let _: BlockingOperator = Operator::new(builder)? diff --git a/core/src/types/operator/builder.rs b/core/src/types/operator/builder.rs index c34fd0309a9..94e0b87bb09 100644 --- a/core/src/types/operator/builder.rs +++ b/core/src/types/operator/builder.rs @@ -32,11 +32,7 @@ use crate::*; /// use opendal::Operator; /// async fn test() -> Result<()> { /// // Create fs backend builder. -/// let mut builder = Fs::default(); -/// // Set the root for fs, all operations will happen under this root. -/// // -/// // NOTE: the root must be absolute path. -/// builder.root("/tmp"); +/// let builder = Fs::default().root("/tmp"); /// /// // Build an `Operator` to start operating the storage. /// let op: Operator = Operator::new(builder)?.finish(); @@ -60,11 +56,7 @@ impl Operator { /// use opendal::Operator; /// async fn test() -> Result<()> { /// // Create fs backend builder. - /// let mut builder = Fs::default(); - /// // Set the root for fs, all operations will happen under this root. - /// // - /// // NOTE: the root must be absolute path. - /// builder.root("/tmp"); + /// let builder = Fs::default().root("/tmp"); /// /// // Build an `Operator` to start operating the storage. /// let op: Operator = Operator::new(builder)?.finish(); diff --git a/core/src/types/operator/operator.rs b/core/src/types/operator/operator.rs index 5f18ef9f36b..7b4ef460d2d 100644 --- a/core/src/types/operator/operator.rs +++ b/core/src/types/operator/operator.rs @@ -48,11 +48,7 @@ use crate::*; /// use opendal::Operator; /// async fn test() -> Result<()> { /// // Create fs backend builder. -/// let mut builder = Fs::default(); -/// // Set the root for fs, all operations will happen under this root. -/// // -/// // NOTE: the root must be absolute path. -/// builder.root("/tmp"); +/// let mut builder = Fs::default().root("/tmp"); /// /// // Build an `Operator` to start operating the storage. /// let _: Operator = Operator::new(builder)?.finish(); diff --git a/integrations/cloudfilter/examples/readonly.rs b/integrations/cloudfilter/examples/readonly.rs index c48e2c188a1..a5636cec91e 100644 --- a/integrations/cloudfilter/examples/readonly.rs +++ b/integrations/cloudfilter/examples/readonly.rs @@ -20,8 +20,7 @@ async fn main() { let root = env::var("ROOT").expect("$ROOT is set"); let client_path = env::var("CLIENT_PATH").expect("$CLIENT_PATH is set"); - let mut fs = services::Fs::default(); - fs.root(&root); + let mut fs = services::Fs::default().root(&root); let op = Operator::new(fs).expect("build operator").finish(); diff --git a/integrations/dav-server/tests/test.rs b/integrations/dav-server/tests/test.rs index 0ad79f72076..62c113e6cae 100644 --- a/integrations/dav-server/tests/test.rs +++ b/integrations/dav-server/tests/test.rs @@ -24,8 +24,7 @@ use opendal::Operator; #[tokio::test] async fn test() -> Result<()> { - let mut builder = Fs::default(); - builder.root("/tmp"); + let builder = Fs::default().root("/tmp"); let op = Operator::new(builder)?.finish();