use proc_macro2::TokenStream;
use quote::quote;
use syn::Ident;
use crate::bitfield_impl::SynField;
pub fn debug_impl<'a, I>(struct_ident: &Ident, fields: I) -> TokenStream
where
I: Iterator<Item = SynField<'a>>,
{
let debug_field_impls = fields
.filter_map(SynField::used_field)
.map(|field| field.ident.as_ref().unwrap())
.map(|ident| quote! {
.field(::core::stringify!(#ident), &::fray::debug::PrettyResult::from(&self.try_get::<#ident>()))
});
quote! {
impl ::core::fmt::Debug for #struct_ident {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct(::core::stringify!(#struct_ident))
#(#debug_field_impls)*
.finish()
}
}
}
}