From 6163e708849e5afe171e157bdbc21420ea2a86f1 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 19 Jun 2017 17:49:55 -0700 Subject: Use 'into()' to convert numerical values safely --- src/value.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/value.rs b/src/value.rs index 48553fd..5efdb92 100644 --- a/src/value.rs +++ b/src/value.rs @@ -254,26 +254,24 @@ impl + Hash + Eq, V: Into> From> for Value } macro_rules! impl_into_value { - ($variant:ident : $T:ty) => (impl_into_value!($variant: $T,);); - ($variant:ident : $T:ty, $($extra:tt)*) => ( + ($variant:ident : $T:ty) => { impl From<$T> for Value { #[inline] fn from(val: $T) -> Value { - Value::$variant(val $($extra)*) + Value::$variant(val.into()) } } - ) + } } impl_into_value!(String: String); impl_into_value!(Integer: i64); -impl_into_value!(Integer: isize, as i64); -impl_into_value!(Integer: i32, as i64); -impl_into_value!(Integer: i8, as i64); -impl_into_value!(Integer: u8, as i64); -impl_into_value!(Integer: u32, as i64); +impl_into_value!(Integer: i32); +impl_into_value!(Integer: i8); +impl_into_value!(Integer: u8); +impl_into_value!(Integer: u32); impl_into_value!(Float: f64); -impl_into_value!(Float: f32, as f64); +impl_into_value!(Float: f32); impl_into_value!(Boolean: bool); impl_into_value!(Datetime: Datetime); -- cgit v1.2.3