From 4bfbb5f1fe3cc731a5eb4bdc0ca9db29b8fad049 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Fri, 17 Nov 2017 11:37:23 -0700 Subject: [PATCH] Fix handful of clippy warnings. --- src/error.rs | 3 ++- src/types/from_sql.rs | 15 +++++++++++++-- src/types/time.rs | 2 +- src/types/to_sql.rs | 2 +- src/types/value.rs | 7 +++++-- src/version.rs | 4 ++-- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/error.rs b/src/error.rs index 5b2241a..7bfe057 100644 --- a/src/error.rs +++ b/src/error.rs @@ -166,7 +166,6 @@ impl error::Error for Error { fn cause(&self) -> Option<&error::Error> { match *self { Error::SqliteFailure(ref err, _) => Some(err), - Error::FromSqlConversionFailure(_, _, ref err) => Some(&**err), Error::Utf8Error(ref err) => Some(err), Error::NulError(ref err) => Some(err), @@ -186,6 +185,8 @@ impl error::Error for Error { #[cfg(feature = "functions")] Error::UserFunctionError(ref err) => Some(&**err), + + Error::FromSqlConversionFailure(_, _, ref err) | Error::ToSqlConversionFailure(ref err) => Some(&**err), } } diff --git a/src/types/from_sql.rs b/src/types/from_sql.rs index 2f9bb19..775819c 100644 --- a/src/types/from_sql.rs +++ b/src/types/from_sql.rs @@ -61,12 +61,24 @@ pub trait FromSql: Sized { fn column_result(value: ValueRef) -> FromSqlResult; } +impl FromSql for isize { + fn column_result(value: ValueRef) -> FromSqlResult { + i64::column_result(value).and_then(|i| { + if i < isize::min_value() as i64 || i > isize::max_value() as i64 { + Err(FromSqlError::OutOfRange(i)) + } else { + Ok(i as isize) + } + }) + } +} + macro_rules! from_sql_integral( ($t:ident) => ( impl FromSql for $t { fn column_result(value: ValueRef) -> FromSqlResult { i64::column_result(value).and_then(|i| { - if i < $t::min_value() as i64 || i > $t::max_value() as i64 { + if i < i64::from($t::min_value()) || i > i64::from($t::max_value()) { Err(FromSqlError::OutOfRange(i)) } else { Ok(i as $t) @@ -80,7 +92,6 @@ macro_rules! from_sql_integral( from_sql_integral!(i8); from_sql_integral!(i16); from_sql_integral!(i32); -from_sql_integral!(isize); from_sql_integral!(u8); from_sql_integral!(u16); from_sql_integral!(u32); diff --git a/src/types/time.rs b/src/types/time.rs index 703d70e..f0dd46c 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -3,7 +3,7 @@ extern crate time; use Result; use types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; -const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%S:%f %Z"; +const SQLITE_DATETIME_FMT: &str = "%Y-%m-%d %H:%M:%S:%f %Z"; impl ToSql for time::Timespec { fn to_sql(&self) -> Result { diff --git a/src/types/to_sql.rs b/src/types/to_sql.rs index 21236a1..53e4f38 100644 --- a/src/types/to_sql.rs +++ b/src/types/to_sql.rs @@ -84,7 +84,7 @@ impl<'a, T: ?Sized> ToSql for &'a T where &'a T: Into> { fn to_sql(&self) -> Result { - Ok(ToSqlOutput::from((*self).into())) + Ok((*self).into()) } } diff --git a/src/types/value.rs b/src/types/value.rs index 65dfc94..b8edf91 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -30,11 +30,15 @@ impl From for Value { } } +impl From for Value { + fn from(i: isize) -> Value { Value::Integer(i as i64) } +} + macro_rules! from_i64( ($t:ty) => ( impl From<$t> for Value { fn from(i: $t) -> Value { - Value::Integer(i as i64) + Value::Integer(i64::from(i)) } } ) @@ -43,7 +47,6 @@ macro_rules! from_i64( from_i64!(i8); from_i64!(i16); from_i64!(i32); -from_i64!(isize); from_i64!(u8); from_i64!(u16); from_i64!(u32); diff --git a/src/version.rs b/src/version.rs index 19d0f55..910feb7 100644 --- a/src/version.rs +++ b/src/version.rs @@ -3,14 +3,14 @@ use std::ffi::CStr; /// Returns the SQLite version as an integer; e.g., `3016002` for version 3.16.2. /// -/// See [sqlite3_libversion_number()](https://www.sqlite.org/c3ref/libversion.html). +/// See [`sqlite3_libversion_number()`](https://www.sqlite.org/c3ref/libversion.html). pub fn version_number() -> i32 { unsafe { ffi::sqlite3_libversion_number() } } /// Returns the SQLite version as a string; e.g., `"3.16.2"` for version 3.16.2. /// -/// See [sqlite3_libversion()](https://www.sqlite.org/c3ref/libversion.html). +/// See [`sqlite3_libversion()`](https://www.sqlite.org/c3ref/libversion.html). pub fn version() -> &'static str { let cstr = unsafe { CStr::from_ptr(ffi::sqlite3_libversion()) }; cstr.to_str()