impl ToSql for i8,i16,u8,u16,u32

This commit is contained in:
John Gallagher 2017-01-22 19:55:49 -05:00
parent 68ae7de1d5
commit 7c072bf55e
2 changed files with 39 additions and 5 deletions

View File

@ -57,8 +57,13 @@ macro_rules! to_sql_self(
to_sql_self!(Null);
to_sql_self!(bool);
to_sql_self!(i8);
to_sql_self!(i16);
to_sql_self!(i32);
to_sql_self!(i64);
to_sql_self!(u8);
to_sql_self!(u16);
to_sql_self!(u32);
to_sql_self!(f64);
impl<'a, T: ?Sized> ToSql for &'a T
@ -95,3 +100,21 @@ impl<T: ToSql> ToSql for Option<T> {
}
}
}
#[cfg(test)]
mod test {
use super::ToSql;
fn is_to_sql<T: ToSql>() {}
#[test]
fn test_integral_types() {
is_to_sql::<i8>();
is_to_sql::<i16>();
is_to_sql::<i32>();
is_to_sql::<i64>();
is_to_sql::<u8>();
is_to_sql::<u16>();
is_to_sql::<u32>();
}
}

View File

@ -30,11 +30,22 @@ impl From<bool> for Value {
}
}
impl From<i32> for Value {
fn from(i: i32) -> Value {
macro_rules! from_i64(
($t:ty) => (
impl From<$t> for Value {
fn from(i: $t) -> Value {
Value::Integer(i as i64)
}
}
}
)
);
from_i64!(i8);
from_i64!(i16);
from_i64!(i32);
from_i64!(u8);
from_i64!(u16);
from_i64!(u32);
impl From<i64> for Value {
fn from(i: i64) -> Value {