From 6cdd64c3f1ceb12ab23072cf7be0974e6189e889 Mon Sep 17 00:00:00 2001 From: Yu Li Date: Fri, 8 Nov 2024 20:28:03 +0800 Subject: [PATCH] chore: make all constable fn to const fn. Signed-off-by: Yu Li --- Cargo.lock | 2 +- motore/Cargo.toml | 2 +- motore/src/builder.rs | 2 +- motore/src/layer/ext/map_err.rs | 2 +- motore/src/layer/identity.rs | 2 +- motore/src/layer/layer_fn.rs | 2 +- motore/src/layer/layers.rs | 2 +- motore/src/layer/stack.rs | 2 +- motore/src/layer/tower_adapter.rs | 2 +- motore/src/service/tower_adapter.rs | 4 ++-- motore/src/timeout.rs | 4 ++-- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 649f65b..362ba26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,7 +203,7 @@ dependencies = [ [[package]] name = "motore" -version = "0.4.1" +version = "0.4.2" dependencies = [ "futures", "http", diff --git a/motore/Cargo.toml b/motore/Cargo.toml index 9b7ac0c..34ccee0 100644 --- a/motore/Cargo.toml +++ b/motore/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "motore" -version = "0.4.1" +version = "0.4.2" edition = "2021" description = """ Motore is a library of modular and reusable components for building robust diff --git a/motore/src/builder.rs b/motore/src/builder.rs index 0777abd..cf3916b 100644 --- a/motore/src/builder.rs +++ b/motore/src/builder.rs @@ -23,7 +23,7 @@ impl Default for ServiceBuilder { impl ServiceBuilder { /// Create a new [`ServiceBuilder`]. - pub fn new() -> Self { + pub const fn new() -> Self { ServiceBuilder { layer: Identity::new(), } diff --git a/motore/src/layer/ext/map_err.rs b/motore/src/layer/ext/map_err.rs index 1ca0b20..cd86d5c 100644 --- a/motore/src/layer/ext/map_err.rs +++ b/motore/src/layer/ext/map_err.rs @@ -5,7 +5,7 @@ pub struct MapErrLayer { } impl MapErrLayer { - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { MapErrLayer { f } } } diff --git a/motore/src/layer/identity.rs b/motore/src/layer/identity.rs index 6248e87..431035c 100644 --- a/motore/src/layer/identity.rs +++ b/motore/src/layer/identity.rs @@ -13,7 +13,7 @@ pub struct Identity { impl Identity { /// Create a new `Identity` value - pub fn new() -> Identity { + pub const fn new() -> Identity { Identity { _p: () } } } diff --git a/motore/src/layer/layer_fn.rs b/motore/src/layer/layer_fn.rs index e56299c..e6e1896 100644 --- a/motore/src/layer/layer_fn.rs +++ b/motore/src/layer/layer_fn.rs @@ -63,7 +63,7 @@ use super::Layer; /// let wrapped_service = log_layer.layer(uppercase_service); /// ``` /// [`Service`]: crate::Service -pub fn layer_fn(f: F) -> LayerFn { +pub const fn layer_fn(f: F) -> LayerFn { LayerFn { f } } diff --git a/motore/src/layer/layers.rs b/motore/src/layer/layers.rs index 64d3d90..6584ddc 100644 --- a/motore/src/layer/layers.rs +++ b/motore/src/layer/layers.rs @@ -11,7 +11,7 @@ impl Default for Layers { } impl Layers { - pub fn new(layer: L) -> Self { + pub const fn new(layer: L) -> Self { Layers(layer) } diff --git a/motore/src/layer/stack.rs b/motore/src/layer/stack.rs index dbe0c05..ecb8f3c 100644 --- a/motore/src/layer/stack.rs +++ b/motore/src/layer/stack.rs @@ -11,7 +11,7 @@ pub struct Stack { impl Stack { /// Create a new `Stack`. - pub fn new(inner: Inner, outer: Outer) -> Self { + pub const fn new(inner: Inner, outer: Outer) -> Self { Stack { inner, outer } } } diff --git a/motore/src/layer/tower_adapter.rs b/motore/src/layer/tower_adapter.rs index facc205..774aca5 100644 --- a/motore/src/layer/tower_adapter.rs +++ b/motore/src/layer/tower_adapter.rs @@ -26,7 +26,7 @@ pub struct TowerAdapterLayer { } impl TowerAdapterLayer { - pub fn new(f: F) -> Self { + pub const fn new(f: F) -> Self { Self { f, _phantom: PhantomData, diff --git a/motore/src/service/tower_adapter.rs b/motore/src/service/tower_adapter.rs index 7cd4bd6..44c6977 100644 --- a/motore/src/service/tower_adapter.rs +++ b/motore/src/service/tower_adapter.rs @@ -53,7 +53,7 @@ pub struct Tower { } impl Tower { - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { Self { inner, f, @@ -162,7 +162,7 @@ pub struct Motore { } impl Motore { - pub fn new(inner: S, f: F) -> Self { + pub const fn new(inner: S, f: F) -> Self { Self { inner, f } } } diff --git a/motore/src/timeout.rs b/motore/src/timeout.rs index eb1a74f..e8fa66b 100644 --- a/motore/src/timeout.rs +++ b/motore/src/timeout.rs @@ -13,7 +13,7 @@ pub struct Timeout { } impl Timeout { - pub fn new(inner: S, duration: Option) -> Self { + pub const fn new(inner: S, duration: Option) -> Self { Self { inner, duration } } } @@ -51,7 +51,7 @@ pub struct TimeoutLayer { } impl TimeoutLayer { - pub fn new(duration: Option) -> Self { + pub const fn new(duration: Option) -> Self { TimeoutLayer { duration } } }