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: make some ops new be const fn #5027

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion core/src/raw/http_util/bytes_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl BytesRange {
///
/// - offset=None => `bytes=-<size>`, read `<size>` bytes from end.
/// - offset=Some(0) => `bytes=0-<size>`, read `<size>` bytes from start.
pub fn new(offset: u64, size: Option<u64>) -> Self {
pub const fn new(offset: u64, size: Option<u64>) -> Self {
BytesRange(offset, size)
}

Expand Down
42 changes: 23 additions & 19 deletions core/src/raw/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
}

Expand All @@ -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,
}
}
}

Expand Down Expand Up @@ -104,7 +106,7 @@ pub struct OpList {

impl Default for OpList {
fn default() -> Self {
OpList {
Self {
limit: None,
start_after: None,
recursive: false,
Expand Down Expand Up @@ -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 }
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {}
}
}

Expand All @@ -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 {}
}
}
10 changes: 5 additions & 5 deletions core/src/raw/rps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 }
}

Expand All @@ -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 {}
}
}
Expand All @@ -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 {}
}
}
Expand All @@ -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 {}
}
}
Expand Down
Loading