@@ -553,12 +553,29 @@ where
553
553
..
554
554
} = & tokens;
555
555
556
- let ( impl_generics, type_generics, where_clause) = generics. split_for_impl ( ) ;
556
+ let empty;
557
+ let mut current;
558
+ let generic_names;
557
559
558
- let generic_names = if attr. static_type . is_some ( ) {
559
- vec ! [ ]
560
- } else {
561
- generics. type_params ( ) . map ( |v| & v. ident ) . collect :: < Vec < _ > > ( )
560
+ let ( impl_generics, type_generics, where_clause) = match & attr. impl_params {
561
+ Some ( params) => {
562
+ empty = syn:: Generics :: default ( ) ;
563
+ current = syn:: Generics :: default ( ) ;
564
+
565
+ for p in params {
566
+ current. params . push ( syn:: GenericParam :: Type ( p. clone ( ) ) ) ;
567
+ }
568
+
569
+ let ( impl_generics, _, where_clause) = empty. split_for_impl ( ) ;
570
+ let ( _, type_generics, _) = current. split_for_impl ( ) ;
571
+ generic_names = Vec :: new ( ) ;
572
+ ( impl_generics, type_generics, where_clause)
573
+ }
574
+ None => {
575
+ current = generics;
576
+ generic_names = current. type_params ( ) . map ( |v| & v. ident ) . collect :: < Vec < _ > > ( ) ;
577
+ current. split_for_impl ( )
578
+ }
562
579
} ;
563
580
564
581
let impl_named = if let [ first_name, remainder @ ..] = & generic_names[ ..] {
@@ -720,85 +737,51 @@ where
720
737
}
721
738
} ) ;
722
739
723
- let impl_from_value = ' out: {
724
- if let Some ( path) = attr. from_value {
725
- let ty = match & attr. from_value_params {
726
- Some ( params) => quote ! ( #ident<#params>) ,
727
- None if generics. params . is_empty ( ) => quote ! ( #ident) ,
728
- _ => break ' out None ,
729
- } ;
730
-
731
- Some ( quote ! {
732
- impl #from_value for #ty {
733
- fn from_value( value: Value ) -> #result<Self , #runtime_error> {
734
- #path( value)
735
- }
740
+ let impl_from_value = attr. from_value . as_ref ( ) . map ( |path| {
741
+ quote ! {
742
+ impl #impl_generics #from_value for #ident #type_generics {
743
+ fn from_value( value: #value) -> #result<Self , #runtime_error> {
744
+ #path( value)
736
745
}
737
- } )
738
- } else {
739
- None
746
+ }
740
747
}
741
- } ;
742
-
743
- let impl_from_value_ref = ' out: {
744
- if let Some ( path) = attr. from_value_ref {
745
- let ty = match & attr. from_value_params {
746
- Some ( params) => quote ! ( #ident<#params>) ,
747
- None if generics. params . is_empty ( ) => quote ! ( #ident) ,
748
- _ => break ' out None ,
749
- } ;
750
-
751
- Some ( quote ! {
752
- impl #unsafe_to_ref for #ty {
753
- type Guard = #raw_any_guard;
748
+ } ) ;
754
749
755
- unsafe fn unsafe_to_ref<' a>( value: #value) -> #vm_result<( & ' a Self , Self :: Guard ) > {
756
- let value = #vm_try!( #path( value) ) ;
757
- let ( value, guard) = #ref_:: into_raw( value) ;
758
- #vm_result:: Ok ( ( value. as_ref( ) , guard) )
759
- }
760
- }
750
+ let impl_from_value_ref = attr. from_value_ref . as_ref ( ) . map ( |path| quote ! {
751
+ impl #impl_generics #unsafe_to_ref for #ident #type_generics {
752
+ type Guard = #raw_any_guard;
761
753
762
- impl #from_value for #ref_<#ty> {
763
- fn from_value( value: #value) -> #result<Self , #runtime_error> {
764
- #path( value)
765
- }
766
- }
767
- } )
768
- } else {
769
- None
754
+ unsafe fn unsafe_to_ref<' a>( value: #value) -> #vm_result<( & ' a Self , Self :: Guard ) > {
755
+ let value = #vm_try!( #path( value) ) ;
756
+ let ( value, guard) = #ref_:: into_raw( value) ;
757
+ #vm_result:: Ok ( ( value. as_ref( ) , guard) )
758
+ }
770
759
}
771
- } ;
772
760
773
- let impl_from_value_mut = ' out: {
774
- if let Some ( path) = attr. from_value_mut {
775
- let ty = match & attr. from_value_params {
776
- Some ( params) => quote ! ( #ident<#params>) ,
777
- None if generics. params . is_empty ( ) => quote ! ( #ident) ,
778
- _ => break ' out None ,
779
- } ;
761
+ impl #impl_generics #from_value for #ref_<#ident #type_generics> {
762
+ fn from_value( value: #value) -> #result<Self , #runtime_error> {
763
+ #path( value)
764
+ }
765
+ }
766
+ } ) ;
780
767
781
- Some ( quote ! {
782
- impl #unsafe_to_mut for #ty {
783
- type Guard = #raw_any_guard;
768
+ let impl_from_value_mut = attr . from_value_mut . as_ref ( ) . map ( |path| quote ! {
769
+ impl #impl_generics # unsafe_to_mut for #ident #type_generics {
770
+ type Guard = #raw_any_guard;
784
771
785
- unsafe fn unsafe_to_mut<' a>( value: #value) -> #vm_result<( & ' a mut Self , Self :: Guard ) > {
786
- let value = #vm_try!( #path( value) ) ;
787
- let ( mut value, guard) = #mut_:: into_raw( value) ;
788
- #vm_result:: Ok ( ( value. as_mut( ) , guard) )
789
- }
790
- }
772
+ unsafe fn unsafe_to_mut<' a>( value: #value) -> #vm_result<( & ' a mut Self , Self :: Guard ) > {
773
+ let value = #vm_try!( #path( value) ) ;
774
+ let ( mut value, guard) = #mut_:: into_raw( value) ;
775
+ #vm_result:: Ok ( ( value. as_mut( ) , guard) )
776
+ }
777
+ }
791
778
792
- impl #from_value for #mut_<#ty> {
793
- fn from_value( value: #value) -> #result<Self , #runtime_error> {
794
- #path( value)
795
- }
796
- }
797
- } )
798
- } else {
799
- None
779
+ impl #impl_generics #from_value for #mut_<#ident #type_generics> {
780
+ fn from_value( value: #value) -> #result<Self , #runtime_error> {
781
+ #path( value)
782
+ }
800
783
}
801
- } ;
784
+ } ) ;
802
785
803
786
quote ! {
804
787
#install_with
0 commit comments