Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add a helper macro to reduce the definition of root methods #5037

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions core/src/services/aliyun_drive/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,9 @@ impl Debug for AliyunDriveBuilder {
}
}

impl AliyunDriveBuilder {
/// Set the root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(AliyunDriveBuilder);

impl AliyunDriveBuilder {
/// Set access_token of this backend.
pub fn access_token(mut self, access_token: &str) -> Self {
self.config.access_token = Some(access_token.to_string());
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/alluxio/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,9 @@ impl Debug for AlluxioBuilder {
}
}

impl AlluxioBuilder {
/// Set root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(AlluxioBuilder);

impl AlluxioBuilder {
/// endpoint of this backend.
///
/// Endpoint must be full uri, mostly like `http://127.0.0.1:39999`.
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,9 @@ impl Debug for AzblobBuilder {
}
}

impl AzblobBuilder {
/// Set root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(AzblobBuilder);

impl AzblobBuilder {
/// Set container name of this backend.
pub fn container(mut self, container: &str) -> Self {
self.config.container = container.to_string();
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/azdls/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,9 @@ impl Debug for AzdlsBuilder {
}
}

impl AzdlsBuilder {
/// Set root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(AzdlsBuilder);

impl AzdlsBuilder {
/// Set filesystem name of this backend.
pub fn filesystem(mut self, filesystem: &str) -> Self {
self.config.filesystem = filesystem.to_string();
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/azfile/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,9 @@ impl Debug for AzfileBuilder {
}
}

impl AzfileBuilder {
/// Set root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(AzfileBuilder);

impl AzfileBuilder {
/// Set endpoint of this backend.
pub fn endpoint(mut self, endpoint: &str) -> Self {
if !endpoint.is_empty() {
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/b2/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,9 @@ impl Debug for B2Builder {
}
}

impl B2Builder {
/// Set root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(B2Builder);

impl B2Builder {
/// application_key_id of this backend.
pub fn application_key_id(mut self, application_key_id: &str) -> Self {
self.config.application_key_id = if application_key_id.is_empty() {
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/chainsafe/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,9 @@ impl Debug for ChainsafeBuilder {
}
}

impl ChainsafeBuilder {
/// Set root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(ChainsafeBuilder);

impl ChainsafeBuilder {
/// api_key of this backend.
///
/// required.
Expand Down
13 changes: 2 additions & 11 deletions core/src/services/cloudflare_kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ impl Debug for CloudflareKvBuilder {
}
}

crate::impl_root_for_builder!(CloudflareKvBuilder);

impl CloudflareKvBuilder {
/// Set the token used to authenticate with CloudFlare.
pub fn token(mut self, token: &str) -> Self {
Expand All @@ -112,17 +114,6 @@ impl CloudflareKvBuilder {
}
self
}

/// Set the root within this backend.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
}

impl Builder for CloudflareKvBuilder {
Expand Down
13 changes: 1 addition & 12 deletions core/src/services/compfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,7 @@ pub struct CompfsBuilder {
config: CompfsConfig,
}

impl CompfsBuilder {
/// Set root for Compfs
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
}
crate::impl_root_for_builder!(CompfsBuilder);

impl Builder for CompfsBuilder {
const SCHEME: Scheme = Scheme::Compfs;
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/cos/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,9 @@ impl Debug for CosBuilder {
}
}

impl CosBuilder {
/// Set root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(CosBuilder);

impl CosBuilder {
/// Set endpoint of this backend.
///
/// NOTE: no bucket or account id in endpoint, we will trim them if exists.
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/d1/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ impl Debug for D1Builder {
}
}

crate::impl_root_for_builder!(D1Builder);

impl D1Builder {
/// Set api token for the cloudflare d1 service.
///
Expand Down Expand Up @@ -125,19 +127,6 @@ impl D1Builder {
self
}

/// set the working directory, all operations will be performed under it.
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

/// Set the table name of the d1 service to read/write.
///
/// If not specified, it will return an error when building.
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/dbfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,9 @@ impl Debug for DbfsBuilder {
}
}

impl DbfsBuilder {
/// Set root of this backend.
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(DbfsBuilder);

impl DbfsBuilder {
/// Set endpoint of this backend.
///
/// Endpoint must be full uri, e.g.
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/dropbox/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,9 @@ impl Debug for DropboxBuilder {
}
}

impl DropboxBuilder {
/// Set the root directory for dropbox.
///
/// Default to `/` if not set.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(DropboxBuilder);

impl DropboxBuilder {
/// Access token is used for temporary access to the Dropbox API.
///
/// You can get the access token from [Dropbox App Console](https://www.dropbox.com/developers/apps)
Expand Down
15 changes: 2 additions & 13 deletions core/src/services/etcd/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ impl Debug for EtcdBuilder {
}
}

crate::impl_root_for_builder!(EtcdBuilder);

impl EtcdBuilder {
/// set the network address of etcd service.
///
Expand Down Expand Up @@ -155,19 +157,6 @@ impl EtcdBuilder {
self
}

/// set the working directory, all operations will be performed under it.
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

/// Set the certificate authority file path.
///
/// default is None
Expand Down
13 changes: 2 additions & 11 deletions core/src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,9 @@ pub struct FsBuilder {
config: FsConfig,
}

impl FsBuilder {
/// Set root for backend.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
crate::impl_root_for_builder!(FsBuilder);

impl FsBuilder {
/// Set temp dir for atomic write.
///
/// # Notes
Expand Down
13 changes: 2 additions & 11 deletions core/src/services/ftp/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ impl Debug for FtpBuilder {
}
}

crate::impl_root_for_builder!(FtpBuilder);

impl FtpBuilder {
/// set endpoint for ftp backend.
pub fn endpoint(mut self, endpoint: &str) -> Self {
Expand All @@ -104,17 +106,6 @@ impl FtpBuilder {
self
}

/// set root path for ftp backend.
pub fn root(mut self, root: &str) -> Self {
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

/// set user for ftp backend.
pub fn user(mut self, user: &str) -> Self {
self.config.user = if user.is_empty() {
Expand Down
Loading
Loading