From ee24226d5c94c14254c6a37a31be508b841ef697 Mon Sep 17 00:00:00 2001 From: Paul Nguyen Date: Thu, 5 Jun 2025 16:50:38 +0200 Subject: [PATCH] Tweak Option inference to support more cases with other derive macros --- validator_derive/src/types.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/validator_derive/src/types.rs b/validator_derive/src/types.rs index 54cbcf1b..1bbbe673 100644 --- a/validator_derive/src/types.rs +++ b/validator_derive/src/types.rs @@ -151,7 +151,12 @@ impl ValidateField { /// How many Option u8 { - fn find_option(mut count: u8, ty: &syn::Type) -> u8 { + fn find_option(mut count: u8, mut ty: &syn::Type) -> u8 { + // Unwrap `Type::Group`s, these might occur when used with other derive macros. + while let syn::Type::Group(inner) = ty { + ty = &inner.elem; + } + if let syn::Type::Path(p) = ty { let idents_of_path = p.path.segments.iter().fold(String::new(), |mut acc, v| {