@@ -25,7 +25,7 @@ impl ToSql<TinyInt, Mysql> for i8 {
2525impl FromSql < TinyInt , Mysql > for i8 {
2626 fn from_sql ( value : MysqlValue < ' _ > ) -> deserialize:: Result < Self > {
2727 let bytes = value. as_bytes ( ) ;
28- Ok ( bytes[ 0 ] as i8 )
28+ Ok ( i8 :: from_be_bytes ( [ bytes[ 0 ] ] ) )
2929 }
3030}
3131
@@ -69,12 +69,14 @@ where
6969#[ cfg( feature = "mysql_backend" ) ]
7070impl ToSql < Unsigned < TinyInt > , Mysql > for u8 {
7171 fn to_sql < ' b > ( & ' b self , out : & mut Output < ' b , ' _ , Mysql > ) -> serialize:: Result {
72- ToSql :: < TinyInt , Mysql > :: to_sql ( & ( * self as i8 ) , & mut out. reborrow ( ) )
72+ out. write_u8 ( * self ) ?;
73+ Ok ( IsNull :: No )
7374 }
7475}
7576
7677#[ cfg( feature = "mysql_backend" ) ]
7778impl FromSql < Unsigned < TinyInt > , Mysql > for u8 {
79+ #[ allow( clippy:: cast_possible_wrap, clippy:: cast_sign_loss) ] // that's what we want
7880 fn from_sql ( bytes : MysqlValue < ' _ > ) -> deserialize:: Result < Self > {
7981 let signed: i8 = FromSql :: < TinyInt , Mysql > :: from_sql ( bytes) ?;
8082 Ok ( signed as u8 )
@@ -84,12 +86,18 @@ impl FromSql<Unsigned<TinyInt>, Mysql> for u8 {
8486#[ cfg( feature = "mysql_backend" ) ]
8587impl ToSql < Unsigned < SmallInt > , Mysql > for u16 {
8688 fn to_sql < ' b > ( & ' b self , out : & mut Output < ' b , ' _ , Mysql > ) -> serialize:: Result {
87- ToSql :: < SmallInt , Mysql > :: to_sql ( & ( * self as i16 ) , & mut out. reborrow ( ) )
89+ out. write_u16 :: < NativeEndian > ( * self ) ?;
90+ Ok ( IsNull :: No )
8891 }
8992}
9093
9194#[ cfg( feature = "mysql_backend" ) ]
9295impl FromSql < Unsigned < SmallInt > , Mysql > for u16 {
96+ #[ allow(
97+ clippy:: cast_possible_wrap,
98+ clippy:: cast_sign_loss,
99+ clippy:: cast_possible_truncation
100+ ) ] // that's what we want
93101 fn from_sql ( bytes : MysqlValue < ' _ > ) -> deserialize:: Result < Self > {
94102 let signed: i32 = FromSql :: < Integer , Mysql > :: from_sql ( bytes) ?;
95103 Ok ( signed as u16 )
@@ -99,12 +107,18 @@ impl FromSql<Unsigned<SmallInt>, Mysql> for u16 {
99107#[ cfg( feature = "mysql_backend" ) ]
100108impl ToSql < Unsigned < Integer > , Mysql > for u32 {
101109 fn to_sql < ' b > ( & ' b self , out : & mut Output < ' b , ' _ , Mysql > ) -> serialize:: Result {
102- ToSql :: < Integer , Mysql > :: to_sql ( & ( * self as i32 ) , & mut out. reborrow ( ) )
110+ out. write_u32 :: < NativeEndian > ( * self ) ?;
111+ Ok ( IsNull :: No )
103112 }
104113}
105114
106115#[ cfg( feature = "mysql_backend" ) ]
107116impl FromSql < Unsigned < Integer > , Mysql > for u32 {
117+ #[ allow(
118+ clippy:: cast_possible_wrap,
119+ clippy:: cast_sign_loss,
120+ clippy:: cast_possible_truncation
121+ ) ] // that's what we want
108122 fn from_sql ( bytes : MysqlValue < ' _ > ) -> deserialize:: Result < Self > {
109123 let signed: i64 = FromSql :: < BigInt , Mysql > :: from_sql ( bytes) ?;
110124 Ok ( signed as u32 )
@@ -114,12 +128,18 @@ impl FromSql<Unsigned<Integer>, Mysql> for u32 {
114128#[ cfg( feature = "mysql_backend" ) ]
115129impl ToSql < Unsigned < BigInt > , Mysql > for u64 {
116130 fn to_sql < ' b > ( & ' b self , out : & mut Output < ' b , ' _ , Mysql > ) -> serialize:: Result {
117- ToSql :: < BigInt , Mysql > :: to_sql ( & ( * self as i64 ) , & mut out. reborrow ( ) )
131+ out. write_u64 :: < NativeEndian > ( * self ) ?;
132+ Ok ( IsNull :: No )
118133 }
119134}
120135
121136#[ cfg( feature = "mysql_backend" ) ]
122137impl FromSql < Unsigned < BigInt > , Mysql > for u64 {
138+ #[ allow(
139+ clippy:: cast_possible_wrap,
140+ clippy:: cast_sign_loss,
141+ clippy:: cast_possible_truncation
142+ ) ] // that's what we want
123143 fn from_sql ( bytes : MysqlValue < ' _ > ) -> deserialize:: Result < Self > {
124144 let signed: i64 = FromSql :: < BigInt , Mysql > :: from_sql ( bytes) ?;
125145 Ok ( signed as u64 )
0 commit comments