From 3c9988dd427f329da7b81bc34bcb6d987dcf950f Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Thu, 1 Oct 2020 01:45:18 -0400 Subject: [PATCH] upgrade decimal crate to v2.4, add more robust handling for int conversion errors in AsI64 impls --- Cargo.toml | 2 +- src/lib.rs | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3d61d38..5e74274 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "influx-writer" -version = "0.11.1" +version = "0.12.0" authors = ["Jonathan Strong "] edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index 22ce9e8..dd5dde2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,10 +10,11 @@ extern crate slog; use std::io::Read; use std::sync::Arc; -use crossbeam_channel::{Sender, Receiver, bounded, SendError}; use std::{thread, mem}; use std::time::*; use std::collections::VecDeque; +use std::convert::TryInto; +use crossbeam_channel::{Sender, Receiver, bounded, SendError}; use hyper::status::StatusCode; use hyper::client::response::Response; use hyper::Url; @@ -42,17 +43,19 @@ pub trait AsI64 { fn as_i64(x: Self) -> i64; } -impl AsI64 for i64 { fn as_i64(x: Self) -> i64 { x } } -impl AsI64 for i32 { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for u32 { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for u64 { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for usize { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for f64 { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for f32 { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for u16 { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for i16 { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for u8 { fn as_i64(x: Self) -> i64 { x as i64 } } -impl AsI64 for i8 { fn as_i64(x: Self) -> i64 { x as i64 } } +impl AsI64 for i64 { fn as_i64(x: Self) -> i64 { x } } +impl AsI64 for i32 { fn as_i64(x: Self) -> i64 { x as i64 } } +impl AsI64 for u32 { fn as_i64(x: Self) -> i64 { x as i64 } } +impl AsI64 for u64 { fn as_i64(x: Self) -> i64 { x.try_into().unwrap_or(-999) } } +impl AsI64 for usize { fn as_i64(x: Self) -> i64 { x.try_into().unwrap_or(-999) } } +impl AsI64 for i128 { fn as_i64(x: Self) -> i64 { x.try_into().unwrap_or(-999) } } +impl AsI64 for u128 { fn as_i64(x: Self) -> i64 { x.try_into().unwrap_or(-999) } } +impl AsI64 for f64 { fn as_i64(x: Self) -> i64 { x as i64 } } +impl AsI64 for f32 { fn as_i64(x: Self) -> i64 { x as i64 } } +impl AsI64 for u16 { fn as_i64(x: Self) -> i64 { x as i64 } } +impl AsI64 for i16 { fn as_i64(x: Self) -> i64 { x as i64 } } +impl AsI64 for u8 { fn as_i64(x: Self) -> i64 { x as i64 } } +impl AsI64 for i8 { fn as_i64(x: Self) -> i64 { x as i64 } } /// Created this so I know what types can be passed through the /// `measure!` macro, which used to convert with `as i64` and