Add FromSql/ToSql impls for isize.

This commit is contained in:
John Gallagher 2017-04-05 12:52:37 -04:00
parent ccf1f61127
commit a1206d5076
4 changed files with 15 additions and 0 deletions

View File

@ -1,3 +1,7 @@
# Version 0.10.2 (UPCOMING)
* Adds `FromSql` and `ToSql` impls for `isize`. Documents why `usize` and `u64` are not included.
# Version 0.10.1 (2017-03-03)
* Updates the `bundled` SQLite version to 3.17.0.

View File

@ -49,6 +49,14 @@ impl Error for FromSqlError {
pub type FromSqlResult<T> = Result<T, FromSqlError>;
/// A trait for types that can be created from a SQLite value.
///
/// Note that `FromSql` and `ToSql` are defined for most integral types, but not `u64` or `usize`.
/// This is intentional; SQLite returns integers as signed 64-bit values, which cannot fully
/// represent the range of these types. Rusqlite would have to decide how to handle negative
/// values: return an error or reinterpret as a very large postive numbers, neither of which is
/// guaranteed to be correct for everyone. Callers can work around this by fetching values as i64
/// and then doing the interpretation themselves or by defining a newtype and implementing
/// `FromSql`/`ToSql` for it.
pub trait FromSql: Sized {
fn column_result(value: ValueRef) -> FromSqlResult<Self>;
}
@ -72,6 +80,7 @@ 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

@ -74,6 +74,7 @@ to_sql_self!(i8);
to_sql_self!(i16);
to_sql_self!(i32);
to_sql_self!(i64);
to_sql_self!(isize);
to_sql_self!(u8);
to_sql_self!(u16);
to_sql_self!(u32);

View File

@ -43,6 +43,7 @@ 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);