1
0
mirror of https://github.com/danog/strum.git synced 2024-11-26 20:14:40 +01:00

Add doc comment to EnumIs result (#301)

This commit is contained in:
Wyatt Herkamp 2023-10-15 18:05:55 -04:00 committed by GitHub
parent db553e3dcf
commit af9b15b617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 4 deletions

View File

@ -10,7 +10,6 @@ pub fn enum_is_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
};
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<TokenStream> {
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,

View File

@ -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")]

View File

@ -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")]