From b3133c75c44bc7fa2f0450766beb4566f06c4126 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 21 Aug 2024 16:46:26 +0800 Subject: [PATCH 1/2] feat: make some ops `new` be const fn --- core/src/raw/http_util/bytes_range.rs | 2 +- core/src/raw/ops.rs | 58 ++++++++++++++------------- core/src/raw/rps.rs | 10 ++--- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/core/src/raw/http_util/bytes_range.rs b/core/src/raw/http_util/bytes_range.rs index 2734639e5bc..1a603119e2a 100644 --- a/core/src/raw/http_util/bytes_range.rs +++ b/core/src/raw/http_util/bytes_range.rs @@ -57,7 +57,7 @@ impl BytesRange { /// /// - offset=None => `bytes=-`, read `` bytes from end. /// - offset=Some(0) => `bytes=0-`, read `` bytes from start. - pub fn new(offset: u64, size: Option) -> Self { + pub const fn new(offset: u64, size: Option) -> Self { BytesRange(offset, size) } diff --git a/core/src/raw/ops.rs b/core/src/raw/ops.rs index c18c87961aa..4f398c54946 100644 --- a/core/src/raw/ops.rs +++ b/core/src/raw/ops.rs @@ -35,8 +35,8 @@ pub struct OpCreateDir {} impl OpCreateDir { /// Create a new `OpCreateDir`. - pub fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self {} } } @@ -50,8 +50,10 @@ pub struct OpDelete { impl OpDelete { /// Create a new `OpDelete`. - pub fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self { + version: None, + } } } @@ -104,7 +106,14 @@ pub struct OpList { impl Default for OpList { fn default() -> Self { - OpList { + Self::new() + } +} + +impl OpList { + /// Create a new `OpList`. + pub const fn new() -> Self { + Self { limit: None, start_after: None, recursive: false, @@ -113,13 +122,6 @@ impl Default for OpList { concurrent: 1, } } -} - -impl OpList { - /// Create a new `OpList`. - pub fn new() -> Self { - Self::default() - } /// Change the limit of this list operation. pub fn with_limit(mut self, limit: usize) -> Self { @@ -259,7 +261,7 @@ pub struct OpBatch { impl OpBatch { /// Create a new batch options. - pub fn new(ops: Vec<(String, BatchOperation)>) -> Self { + pub const fn new(ops: Vec<(String, BatchOperation)>) -> Self { Self { ops } } @@ -269,7 +271,7 @@ impl OpBatch { } /// Consume OpBatch into BatchOperation - pub fn into_operation(self) -> Vec<(String, BatchOperation)> { + pub const fn into_operation(self) -> Vec<(String, BatchOperation)> { self.ops } } @@ -439,18 +441,18 @@ pub struct OpReader { impl Default for OpReader { fn default() -> Self { - Self { - concurrent: 1, - chunk: None, - gap: None, - } + Self::new() } } impl OpReader { /// Create a new `OpReader`. - pub fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self { + concurrent: 1, + chunk: None, + gap: None, + } } /// Set the concurrent of the option @@ -700,8 +702,10 @@ pub struct OpWriter { impl OpWriter { /// Create a new `OpWriter`. - pub fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self { + chunk: None, + } } /// Get the chunk from op. @@ -732,8 +736,8 @@ pub struct OpCopy {} impl OpCopy { /// Create a new `OpCopy`. - pub fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self {} } } @@ -743,7 +747,7 @@ pub struct OpRename {} impl OpRename { /// Create a new `OpMove`. - pub fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self {} } } diff --git a/core/src/raw/rps.rs b/core/src/raw/rps.rs index a3073dbd4b7..4c1d27d88fd 100644 --- a/core/src/raw/rps.rs +++ b/core/src/raw/rps.rs @@ -60,7 +60,7 @@ pub struct PresignedRequest { impl PresignedRequest { /// Create a new PresignedRequest - pub fn new(method: http::Method, uri: http::Uri, headers: http::HeaderMap) -> Self { + pub const fn new(method: http::Method, uri: http::Uri, headers: http::HeaderMap) -> Self { Self { method, uri, @@ -195,7 +195,7 @@ pub struct RpStat { impl RpStat { /// Create a new reply for `stat`. - pub fn new(meta: Metadata) -> Self { + pub const fn new(meta: Metadata) -> Self { RpStat { meta } } @@ -217,7 +217,7 @@ pub struct RpWrite {} impl RpWrite { /// Create a new reply for `write`. - pub fn new() -> Self { + pub const fn new() -> Self { Self {} } } @@ -228,7 +228,7 @@ pub struct RpCopy {} impl RpCopy { /// Create a new reply for `copy`. - pub fn new() -> Self { + pub const fn new() -> Self { Self {} } } @@ -239,7 +239,7 @@ pub struct RpRename {} impl RpRename { /// Create a new reply for `rename`. - pub fn new() -> Self { + pub const fn new() -> Self { Self {} } } From ef81d21ddace072b9e4f22d39cf2514e1901c747 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 22 Aug 2024 15:22:53 +0800 Subject: [PATCH 2/2] revert some --- core/src/raw/ops.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/raw/ops.rs b/core/src/raw/ops.rs index 4f398c54946..c78de7e41eb 100644 --- a/core/src/raw/ops.rs +++ b/core/src/raw/ops.rs @@ -106,13 +106,6 @@ pub struct OpList { impl Default for OpList { fn default() -> Self { - Self::new() - } -} - -impl OpList { - /// Create a new `OpList`. - pub const fn new() -> Self { Self { limit: None, start_after: None, @@ -122,6 +115,13 @@ impl OpList { concurrent: 1, } } +} + +impl OpList { + /// Create a new `OpList`. + pub fn new() -> Self { + Self::default() + } /// Change the limit of this list operation. pub fn with_limit(mut self, limit: usize) -> Self { @@ -271,7 +271,7 @@ impl OpBatch { } /// Consume OpBatch into BatchOperation - pub const fn into_operation(self) -> Vec<(String, BatchOperation)> { + pub fn into_operation(self) -> Vec<(String, BatchOperation)> { self.ops } }