From 7cce17d66214025e819d5a2af12861ae6a236c55 Mon Sep 17 00:00:00 2001 From: "Lan, Jian" Date: Sun, 1 Mar 2026 01:19:05 +0800 Subject: [PATCH] refactor: make qualified functions `const fn` --- patchable-macro/src/context.rs | 6 +++--- patchable/tests/common/mod.rs | 2 +- patchable/tests/no_serde.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/patchable-macro/src/context.rs b/patchable-macro/src/context.rs index 92756e5..f6f550f 100644 --- a/patchable-macro/src/context.rs +++ b/patchable-macro/src/context.rs @@ -306,19 +306,19 @@ impl<'a> FieldAction<'a> { } } - fn member(&self) -> &FieldMember<'a> { + const fn member(&self) -> &FieldMember<'a> { match self { FieldAction::Keep { member, .. } | FieldAction::Patch { member, .. } => member, } } - fn ty(&self) -> &'a Type { + const fn ty(&self) -> &'a Type { match self { FieldAction::Keep { ty, .. } | FieldAction::Patch { ty, .. } => ty, } } - fn is_patch(&self) -> bool { + const fn is_patch(&self) -> bool { matches!(self, FieldAction::Patch { .. }) } diff --git a/patchable/tests/common/mod.rs b/patchable/tests/common/mod.rs index 8969b02..50cee40 100644 --- a/patchable/tests/common/mod.rs +++ b/patchable/tests/common/mod.rs @@ -1,7 +1,7 @@ use patchable::patchable_model; use serde::{Deserialize, Serialize}; -pub fn identity(x: &i32) -> i32 { +pub const fn identity(x: &i32) -> i32 { *x } diff --git a/patchable/tests/no_serde.rs b/patchable/tests/no_serde.rs index 69b8267..9172388 100644 --- a/patchable/tests/no_serde.rs +++ b/patchable/tests/no_serde.rs @@ -1,6 +1,6 @@ use patchable::patchable_model; -fn plus_one(x: i32) -> i32 { +const fn plus_one(x: i32) -> i32 { x + 1 }