fn generate_struct(input: &DeriveInput, tla: &TopLevelAttrs, ds: &DataStruct) -> Result<TokenStream, CompileError> {
    let (field_attrs, (name, ty, struct_type))
        = (get_struct_field_attrs(&ds)?, get_struct_names_types(&ds));
    
    let read_struct_body = generate_body(tla, &field_attrs, &name, ty)?;
    
    let struct_name = input.ident.to_string();
    let struct_assertions = get_assertions(&tla.assert);

    let write_start_struct = write_start_struct(&struct_name);
    let write_end_struct = write_end_struct();

    let name = get_struct_permenant_names(&ds);

    let build_struct = match struct_type {
        StructType::Fields => quote!{Ok(Self { #(#name),* })},
        StructType::Tuple => quote!{Ok(Self ( #(#name),* ))},
        StructType::Unit => return Ok(quote!{Ok(Self)}),
    };

    Ok(quote!{
        #write_start_struct

        #read_struct_body

        #write_end_struct

        #(
            #struct_assertions
        )*

        #build_struct
    })
}
// TODO: replace all functions that are only passed tla with a method on TopLevelAttrs
replace all functions that are only passed tla with a method on TopLevelAttrs
replace all functions that are only passed tla with a method on TopLevelAttrs
fn generate_struct(input: &DeriveInput, tla: &TopLevelAttrs, ds: &DataStruct) -> Result<TokenStream, CompileError> {
    let (field_attrs, (name, ty, struct_type))
        = (get_struct_field_attrs(&ds)?, get_struct_names_types(&ds));
    let read_struct_body = generate_body(tla, &field_attrs, &name, ty)?;
    let struct_name = input.ident.to_string();
    let struct_assertions = get_assertions(&tla.assert);
    let write_start_struct = write_start_struct(&struct_name);
    let write_end_struct = write_end_struct();
    let name = get_struct_permenant_names(&ds);
    let build_struct = match struct_type {
        StructType::Fields => quote!{Ok(Self { #(#name),* })},
        StructType::Tuple => quote!{Ok(Self ( #(#name),* ))},
        StructType::Unit => return Ok(quote!{Ok(Self)}),
    };
    Ok(quote!{
        #write_start_struct
        #read_struct_body
        #write_end_struct
        #(
            #struct_assertions
        )*
        #build_struct
    })
}
fn generate_struct ( input : & DeriveInput , tla : & TopLevelAttrs , ds : & DataStruct ) -> Result < TokenStream , CompileError > { let ( field_attrs , ( name , ty , struct_type ) ) = ( get_struct_field_attrs ( & ds ) ? , get_struct_names_types ( & ds ) ) ; let read_struct_body = generate_body ( tla , & field_attrs , & name , ty ) ? ; let struct_name = input . ident . to_string ( ) ; let struct_assertions = get_assertions ( & tla . assert ) ; let write_start_struct = write_start_struct ( & struct_name ) ; let write_end_struct = write_end_struct ( ) ; let name = get_struct_permenant_names ( & ds ) ; let build_struct = match struct_type { StructType :: Fields => quote ! { Ok ( Self { ( name ) } ) } , StructType :: Tuple => quote ! { Ok ( Self ( ( name ) ) ) } , StructType :: Unit => return Ok ( quote ! { Ok ( Self ) } ) , } ; Ok ( quote ! { write_start_struct read_struct_body write_end_struct ( struct_assertions ) build_struct } ) }
TODO: replace all functions that are only passed tla with a method on TopLevelAttrs
TODO : replace all functions that are only passed tla with a method on TopLevelAttrs
input
&DeriveInput
tla
&TopLevelAttrs
ds
&DataStruct