From af9b15b617ed35458fcb5c9247fca5348c357c89 Mon Sep 17 00:00:00 2001 From: Wyatt Herkamp Date: Sun, 15 Oct 2023 18:05:55 -0400 Subject: [PATCH] Add doc comment to EnumIs result (#301) --- strum_macros/src/macros/enum_is.rs | 4 ++-- strum_tests/src/lib.rs | 3 ++- strum_tests/src/main.rs | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/strum_macros/src/macros/enum_is.rs b/strum_macros/src/macros/enum_is.rs index b69fa0c..6cf5645 100644 --- a/strum_macros/src/macros/enum_is.rs +++ b/strum_macros/src/macros/enum_is.rs @@ -10,7 +10,6 @@ pub fn enum_is_inner(ast: &DeriveInput) -> syn::Result { }; let enum_name = &ast.ident; - let variants: Vec<_> = variants .iter() .filter_map(|variant| { @@ -20,10 +19,11 @@ pub fn enum_is_inner(ast: &DeriveInput) -> syn::Result { let variant_name = &variant.ident; let fn_name = format_ident!("is_{}", snakify(&variant_name.to_string())); - + let doc_comment = format!("Returns [true] if the enum is [{}::{}] otherwise [false]", enum_name, variant_name); Some(quote! { #[must_use] #[inline] + #[doc = #doc_comment] pub const fn #fn_name(&self) -> bool { match self { &#enum_name::#variant_name { .. } => true, diff --git a/strum_tests/src/lib.rs b/strum_tests/src/lib.rs index 3addd0d..eb3f65d 100644 --- a/strum_tests/src/lib.rs +++ b/strum_tests/src/lib.rs @@ -1,6 +1,7 @@ use strum::{Display, EnumCount, EnumDiscriminants, EnumString}; +use strum_macros::EnumIs; -#[derive(Debug, Eq, PartialEq, EnumString, Display, EnumCount, EnumDiscriminants)] +#[derive(Debug, Eq, PartialEq, EnumString, Display, EnumCount, EnumDiscriminants, EnumIs)] pub enum Color { /// Docs on red #[strum(to_string = "RedRed")] diff --git a/strum_tests/src/main.rs b/strum_tests/src/main.rs index 4d048a6..97e348a 100644 --- a/strum_tests/src/main.rs +++ b/strum_tests/src/main.rs @@ -1,7 +1,8 @@ use strum::{Display, EnumCount, EnumDiscriminants, EnumString}; +use strum_macros::EnumIs; #[allow(dead_code)] -#[derive(Debug, Eq, PartialEq, EnumString, Display, EnumCount, EnumDiscriminants)] +#[derive(Debug, Eq, PartialEq, EnumString, Display, EnumCount, EnumDiscriminants, EnumIs)] enum Color { /// Random Docs #[strum(to_string = "RedRed")]