From a39f6e97bd7151713c4fd40bf029307a26659b8f Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Tue, 12 Aug 2025 15:59:09 +0300 Subject: [PATCH] feat: make is_valid a constant functionin `#[derive(::prost::Enumeration)]` --- README.md | 2 +- prost-derive/src/lib.rs | 2 +- prost/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36dd5f1d1..ff77d00a8 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ The `#[derive(::prost::Enumeration)]` annotation added to the generated ```rust,ignore impl PhoneType { - pub fn is_valid(value: i32) -> bool { ... } + pub const fn is_valid(value: i32) -> bool { ... } #[deprecated] pub fn from_i32(value: i32) -> Option { ... } } diff --git a/prost-derive/src/lib.rs b/prost-derive/src/lib.rs index 3289da9bf..a300082f1 100644 --- a/prost-derive/src/lib.rs +++ b/prost-derive/src/lib.rs @@ -317,7 +317,7 @@ fn try_enumeration(input: TokenStream) -> Result { let expanded = quote! { impl #impl_generics #ident #ty_generics #where_clause { #[doc=#is_valid_doc] - pub fn is_valid(value: i32) -> bool { + pub const fn is_valid(value: i32) -> bool { match value { #(#is_valid,)* _ => false, diff --git a/prost/README.md b/prost/README.md index 36dd5f1d1..ff77d00a8 100644 --- a/prost/README.md +++ b/prost/README.md @@ -164,7 +164,7 @@ The `#[derive(::prost::Enumeration)]` annotation added to the generated ```rust,ignore impl PhoneType { - pub fn is_valid(value: i32) -> bool { ... } + pub const fn is_valid(value: i32) -> bool { ... } #[deprecated] pub fn from_i32(value: i32) -> Option { ... } }