@@ -98,21 +98,27 @@ fn expand_derive_encode_weak_enum(
9898) -> syn:: Result < proc_macro2:: TokenStream > {
9999 let attr = check_weak_enum_attributes ( input, & variants) ?;
100100 let repr = attr. repr . unwrap ( ) ;
101-
102101 let ident = & input. ident ;
103102
103+ let mut values = Vec :: new ( ) ;
104+
105+ for v in variants {
106+ let id = & v. ident ;
107+ values. push ( quote ! ( #ident :: #id => ( #ident :: #id as #repr) , ) ) ;
108+ }
109+
104110 Ok ( quote ! (
105111 impl <' q, DB : sqlx:: Database > sqlx:: encode:: Encode <' q, DB > for #ident where #repr: sqlx:: encode:: Encode <' q, DB > {
106112 fn encode_by_ref( & self , buf: & mut <DB as sqlx:: database:: HasArguments <' q>>:: ArgumentBuffer ) -> sqlx:: encode:: IsNull {
107- <#repr as sqlx:: encode:: Encode <DB >>:: encode_by_ref( & ( * self as #repr) , buf)
108- }
113+ let value = match self {
114+ #( #values) *
115+ } ;
109116
110- fn produces( & self ) -> Option <DB :: TypeInfo > {
111- <#repr as sqlx:: encode:: Encode <DB >>:: produces( & ( * self as #repr) )
117+ <#repr as sqlx:: encode:: Encode <DB >>:: encode_by_ref( & value, buf)
112118 }
113119
114120 fn size_hint( & self ) -> usize {
115- <#repr as sqlx:: encode:: Encode <DB >>:: size_hint( & ( * self as #repr ) )
121+ <#repr as sqlx:: encode:: Encode <DB >>:: size_hint( & Default :: default ( ) )
116122 }
117123 }
118124 ) )
@@ -127,6 +133,7 @@ fn expand_derive_encode_strong_enum(
127133 let ident = & input. ident ;
128134
129135 let mut value_arms = Vec :: new ( ) ;
136+
130137 for v in variants {
131138 let id = & v. ident ;
132139 let attributes = parse_child_attributes ( & v. attrs ) ?;
0 commit comments