@@ -98,21 +98,27 @@ fn expand_derive_encode_weak_enum(
98
98
) -> syn:: Result < proc_macro2:: TokenStream > {
99
99
let attr = check_weak_enum_attributes ( input, & variants) ?;
100
100
let repr = attr. repr . unwrap ( ) ;
101
-
102
101
let ident = & input. ident ;
103
102
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
+
104
110
Ok ( quote ! (
105
111
impl <' q, DB : sqlx:: Database > sqlx:: encode:: Encode <' q, DB > for #ident where #repr: sqlx:: encode:: Encode <' q, DB > {
106
112
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
+ } ;
109
116
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)
112
118
}
113
119
114
120
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 ( ) )
116
122
}
117
123
}
118
124
) )
@@ -127,6 +133,7 @@ fn expand_derive_encode_strong_enum(
127
133
let ident = & input. ident ;
128
134
129
135
let mut value_arms = Vec :: new ( ) ;
136
+
130
137
for v in variants {
131
138
let id = & v. ident ;
132
139
let attributes = parse_child_attributes ( & v. attrs ) ?;
0 commit comments