fray-macro 0.1.2

Macros to generate bitfield structs for fray
Documentation
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()
            }
        }
    }
}

// pub fn into_inner(struct_ident: &Ident) -> TokenStream {
//     quote! {
//         impl ::core::convert::From<#struct_ident> for <<#struct_ident as ::fray::BitFieldImpl>::Container as ::fray::BitContainer>::Inner {
//             fn from(value: #struct_ident) -> Self {
//                 <#struct_ident as ::fray::BitField>::into_inner(value)
//             }
//         }
//     }
// }