@@ -127,3 +127,88 @@ impl Decode<'_, Postgres> for i64 {
127127 } )
128128 }
129129}
130+
131+ impl Type < Postgres > for u16 {
132+ fn type_info ( ) -> PgTypeInfo {
133+ PgTypeInfo :: INT4
134+ }
135+ }
136+
137+ impl PgHasArrayType for u16 {
138+ fn array_type_info ( ) -> PgTypeInfo {
139+ PgTypeInfo :: INT4_ARRAY
140+ }
141+ }
142+
143+ impl Encode < ' _ , Postgres > for u16 {
144+ fn encode_by_ref ( & self , buf : & mut PgArgumentBuffer ) -> IsNull {
145+ buf. extend ( & i32:: from ( * self ) . to_be_bytes ( ) ) ;
146+ IsNull :: No
147+ }
148+ }
149+
150+ impl Decode < ' _ , Postgres > for u16 {
151+ fn decode ( value : PgValueRef < ' _ > ) -> Result < Self , BoxDynError > {
152+ let decoded = match value. format ( ) {
153+ PgValueFormat :: Binary => BigEndian :: read_i32 ( value. as_bytes ( ) ?) ,
154+ PgValueFormat :: Text => value. as_str ( ) ?. parse :: < i32 > ( ) ?,
155+ } ;
156+ Ok ( u16:: try_from ( decoded) ?)
157+ }
158+ }
159+
160+ impl Type < Postgres > for u32 {
161+ fn type_info ( ) -> PgTypeInfo {
162+ PgTypeInfo :: INT8
163+ }
164+ }
165+
166+ impl PgHasArrayType for u32 {
167+ fn array_type_info ( ) -> PgTypeInfo {
168+ PgTypeInfo :: INT8_ARRAY
169+ }
170+ }
171+
172+ impl Encode < ' _ , Postgres > for u32 {
173+ fn encode_by_ref ( & self , buf : & mut PgArgumentBuffer ) -> IsNull {
174+ buf. extend ( & i64:: from ( * self ) . to_be_bytes ( ) ) ;
175+ IsNull :: No
176+ }
177+ }
178+
179+ impl Decode < ' _ , Postgres > for u32 {
180+ fn decode ( value : PgValueRef < ' _ > ) -> Result < Self , BoxDynError > {
181+ let decoded = match value. format ( ) {
182+ PgValueFormat :: Binary => BigEndian :: read_i64 ( value. as_bytes ( ) ?) ,
183+ PgValueFormat :: Text => value. as_str ( ) ?. parse :: < i64 > ( ) ?,
184+ } ;
185+ Ok ( u32:: try_from ( decoded) ?)
186+ }
187+ }
188+
189+ impl Type < Postgres > for u64 {
190+ fn type_info ( ) -> PgTypeInfo {
191+ PgTypeInfo :: NUMERIC
192+ }
193+ }
194+
195+ impl PgHasArrayType for u64 {
196+ fn array_type_info ( ) -> PgTypeInfo {
197+ PgTypeInfo :: NUMERIC_ARRAY
198+ }
199+ }
200+
201+ impl Encode < ' _ , Postgres > for u64 {
202+ fn encode_by_ref ( & self , buf : & mut PgArgumentBuffer ) -> IsNull {
203+ let numeric_str = self . to_string ( ) ;
204+ buf. extend ( numeric_str. as_bytes ( ) ) ;
205+ IsNull :: No
206+ }
207+ }
208+
209+ impl Decode < ' _ , Postgres > for u64 {
210+ fn decode ( value : PgValueRef < ' _ > ) -> Result < Self , BoxDynError > {
211+ let decoded = value. as_str ( ) ?. parse :: < u64 > ( ) ?;
212+ Ok ( decoded)
213+ }
214+ }
0 commit comments