fix(mysql): allow reading a bool from any integer type

This commit is contained in:
Ryan Leckey 2021-02-27 13:53:10 -08:00
parent 635bb3e8f1
commit c9197916fb
No known key found for this signature in database
GPG Key ID: F8AA68C235AB08C9

View File

@ -18,13 +18,13 @@ impl Type<MySql> for bool {
impl Encode<MySql> for bool {
fn encode(&self, ty: &MySqlTypeInfo, out: &mut MySqlOutput<'_>) -> encode::Result<()> {
<u8 as Encode<MySql>>::encode(&(*self as u8), ty, out)
<i128 as Encode<MySql>>::encode(&(*self as i128), ty, out)
}
}
impl<'r> Decode<'r, MySql> for bool {
fn decode(raw: MySqlRawValue<'r>) -> decode::Result<Self> {
Ok(raw.decode::<u8>()? != 0)
Ok(raw.decode::<i128>()? != 0)
}
}