Fix handful of clippy warnings.

This commit is contained in:
John Gallagher 2017-11-17 11:37:23 -07:00
parent 5f180c5a95
commit 4bfbb5f1fe
6 changed files with 24 additions and 9 deletions

View File

@ -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),
}
}

View File

@ -61,12 +61,24 @@ pub trait FromSql: Sized {
fn column_result(value: ValueRef) -> FromSqlResult<Self>;
}
impl FromSql for isize {
fn column_result(value: ValueRef) -> FromSqlResult<Self> {
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<Self> {
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);

View File

@ -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<ToSqlOutput> {

View File

@ -84,7 +84,7 @@ impl<'a, T: ?Sized> ToSql for &'a T
where &'a T: Into<ToSqlOutput<'a>>
{
fn to_sql(&self) -> Result<ToSqlOutput> {
Ok(ToSqlOutput::from((*self).into()))
Ok((*self).into())
}
}

View File

@ -30,11 +30,15 @@ impl From<bool> for Value {
}
}
impl From<isize> 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);

View File

@ -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()