@@ -36,6 +36,7 @@ use blocks::*;
36
36
37
37
const DEFAULT_IMPORTS : & ' static str = "
38
38
use alloc::str::FromStr;
39
+ use alloc::string::String;
39
40
use core::ffi::c_void;
40
41
use core::convert::Infallible;
41
42
use bitcoin::hashes::Hash;
@@ -533,8 +534,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
533
534
writeln!( w, "\t type {} = crate::{};" , t. ident, $type_resolver. resolve_path( & tr. path, Some ( & gen_types) ) ) . unwrap( ) ;
534
535
for bound in bounds_iter {
535
536
if let syn:: TypeParamBound :: Trait ( t) = bound {
536
- // We only allow for `?Sized` here.
537
- if let syn:: TraitBoundModifier :: Maybe ( _) = t. modifier { } else { panic!( ) ; }
537
+ // We only allow for `Sized` here.
538
538
assert_eq!( t. path. segments. len( ) , 1 ) ;
539
539
assert_eq!( format!( "{}" , t. path. segments[ 0 ] . ident) , "Sized" ) ;
540
540
}
@@ -554,8 +554,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
554
554
writeln ! ( w, "unsafe impl Send for {} {{}}" , trait_name) . unwrap ( ) ;
555
555
writeln ! ( w, "unsafe impl Sync for {} {{}}" , trait_name) . unwrap ( ) ;
556
556
557
- writeln ! ( w, "#[no_mangle]" ) . unwrap ( ) ;
558
- writeln ! ( w, "pub(crate) extern \" C\" fn {}_clone_fields(orig: &{}) -> {} {{" , trait_name, trait_name, trait_name) . unwrap ( ) ;
557
+ writeln ! ( w, "pub(crate) fn {}_clone_fields(orig: &{}) -> {} {{" , trait_name, trait_name, trait_name) . unwrap ( ) ;
559
558
writeln ! ( w, "\t {} {{" , trait_name) . unwrap ( ) ;
560
559
writeln ! ( w, "\t \t this_arg: orig.this_arg," ) . unwrap ( ) ;
561
560
for ( field, clone_fn, _) in generated_fields. iter ( ) {
@@ -647,6 +646,8 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
647
646
writeln ! ( w, "// directly as a Deref trait in higher-level structs:" ) . unwrap ( ) ;
648
647
writeln ! ( w, "impl core::ops::Deref for {} {{\n \t type Target = Self;" , trait_name) . unwrap ( ) ;
649
648
writeln ! ( w, "\t fn deref(&self) -> &Self {{\n \t \t self\n \t }}\n }}" ) . unwrap ( ) ;
649
+ writeln ! ( w, "impl core::ops::DerefMut for {} {{" , trait_name) . unwrap ( ) ;
650
+ writeln ! ( w, "\t fn deref_mut(&mut self) -> &mut Self {{\n \t \t self\n \t }}\n }}" ) . unwrap ( ) ;
650
651
}
651
652
652
653
writeln ! ( w, "/// Calls the free function if one is set" ) . unwrap ( ) ;
@@ -811,6 +812,19 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
811
812
if all_fields_settable {
812
813
// Build a constructor!
813
814
writeln ! ( w, "/// Constructs a new {} given each field" , struct_name) . unwrap ( ) ;
815
+ match & s. fields {
816
+ syn:: Fields :: Named ( fields) => {
817
+ writeln_arg_docs ( w, & [ ] , "" , types, Some ( & gen_types) ,
818
+ fields. named . iter ( ) . map ( |field| ( format ! ( "{}_arg" , field. ident. as_ref( ) . unwrap( ) ) , & field. ty ) ) ,
819
+ None ) ;
820
+ } ,
821
+ syn:: Fields :: Unnamed ( fields) => {
822
+ writeln_arg_docs ( w, & [ ] , "" , types, Some ( & gen_types) ,
823
+ fields. unnamed . iter ( ) . enumerate ( ) . map ( |( idx, field) | ( format ! ( "{}_arg" , ( 'a' as u8 + idx as u8 ) ) , & field. ty ) ) ,
824
+ None ) ;
825
+ } ,
826
+ syn:: Fields :: Unit => { } ,
827
+ }
814
828
write ! ( w, "#[must_use]\n #[no_mangle]\n pub extern \" C\" fn {}_new(" , struct_name) . unwrap ( ) ;
815
829
816
830
match & s. fields {
0 commit comments