From 636eee4a25d8e7693b7eb4a9cb08453ef25f4044 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 16 Mar 2022 21:15:13 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20treat=20all=20numbers=20as=20de?= =?UTF-8?q?cimals=20unless=20necessary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/sql/number.rs | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/lib/src/sql/number.rs b/lib/src/sql/number.rs index 07ae865c..4556c662 100644 --- a/lib/src/sql/number.rs +++ b/lib/src/sql/number.rs @@ -29,91 +29,79 @@ pub enum Number { impl Default for Number { fn default() -> Self { - Number::Decimal(Decimal::from(0)) + Number::Int(0) } } impl From for Number { fn from(i: i8) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: i16) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: i32) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: i64) -> Self { - Number::Decimal(Decimal::from(i)) - } -} - -impl From for Number { - fn from(i: i128) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: isize) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: u8) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: u16) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: u32) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: u64) -> Self { - Number::Decimal(Decimal::from(i)) - } -} - -impl From for Number { - fn from(i: u128) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(i: usize) -> Self { - Number::Decimal(Decimal::from(i)) + Number::Int(i as i64) } } impl From for Number { fn from(f: f32) -> Self { - Number::Decimal(Decimal::from_f32(f).unwrap_or_default()) + Number::Float(f as f64) } } impl From for Number { fn from(f: f64) -> Self { - Number::Decimal(Decimal::from_f64(f).unwrap_or_default()) + Number::Float(f as f64) } }