diff --git a/strum_macros/src/macros/enum_iter.rs b/strum_macros/src/macros/enum_iter.rs index 203b926..d136d30 100644 --- a/strum_macros/src/macros/enum_iter.rs +++ b/strum_macros/src/macros/enum_iter.rs @@ -65,11 +65,14 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result { arms.push(quote! { _ => ::core::option::Option::None }); let iter_name = syn::parse_str::(&format!("{}Iter", name)).unwrap(); + // Create a string literal "MyEnumIter" to use in the debug impl. + let iter_name_debug_struct = + syn::parse_str::(&format!("\"{}\"", iter_name)).unwrap(); + Ok(quote! { #[doc = #doc_comment] #[allow( missing_copy_implementations, - missing_debug_implementations, )] #vis struct #iter_name #ty_generics { idx: usize, @@ -77,6 +80,16 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result { marker: ::core::marker::PhantomData #phantom_data, } + impl #impl_generics core::fmt::Debug for #iter_name #ty_generics #where_clause { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + // We don't know if the variants implement debug themselves so the only thing we + // can really show is how many elements are left. + f.debug_struct(#iter_name_debug_struct) + .field("len", &self.len()) + .finish() + } + } + impl #impl_generics #iter_name #ty_generics #where_clause { fn get(&self, idx: usize) -> Option<#name #ty_generics> { match idx {