aboutsummaryrefslogtreecommitdiff
path: root/src/types/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types/mod.rs')
-rw-r--r--src/types/mod.rs69
1 files changed, 25 insertions, 44 deletions
diff --git a/src/types/mod.rs b/src/types/mod.rs
index 4e524b2..4000ae2 100644
--- a/src/types/mod.rs
+++ b/src/types/mod.rs
@@ -110,7 +110,7 @@ pub struct Null;
/// SQLite data types.
/// See [Fundamental Datatypes](https://sqlite.org/c3ref/c_blob.html).
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Type {
/// NULL
Null,
@@ -140,7 +140,6 @@ impl fmt::Display for Type {
mod test {
use super::Value;
use crate::{params, Connection, Error, Result, Statement};
- use std::f64::EPSILON;
use std::os::raw::{c_double, c_int};
fn checked_memory_handle() -> Result<Connection> {
@@ -264,7 +263,7 @@ mod test {
assert_eq!(vec![1, 2], row.get::<_, Vec<u8>>(0)?);
assert_eq!("text", row.get::<_, String>(1)?);
assert_eq!(1, row.get::<_, c_int>(2)?);
- assert!((1.5 - row.get::<_, c_double>(3)?).abs() < EPSILON);
+ assert!((1.5 - row.get::<_, c_double>(3)?).abs() < f64::EPSILON);
assert_eq!(row.get::<_, Option<c_int>>(4)?, None);
assert_eq!(row.get::<_, Option<c_double>>(4)?, None);
assert_eq!(row.get::<_, Option<String>>(4)?, None);
@@ -272,85 +271,67 @@ mod test {
// check some invalid types
// 0 is actually a blob (Vec<u8>)
- assert!(is_invalid_column_type(
- row.get::<_, c_int>(0).err().unwrap()
- ));
- assert!(is_invalid_column_type(
- row.get::<_, c_int>(0).err().unwrap()
- ));
+ assert!(is_invalid_column_type(row.get::<_, c_int>(0).unwrap_err()));
+ assert!(is_invalid_column_type(row.get::<_, c_int>(0).unwrap_err()));
assert!(is_invalid_column_type(row.get::<_, i64>(0).err().unwrap()));
assert!(is_invalid_column_type(
- row.get::<_, c_double>(0).err().unwrap()
- ));
- assert!(is_invalid_column_type(
- row.get::<_, String>(0).err().unwrap()
+ row.get::<_, c_double>(0).unwrap_err()
));
+ assert!(is_invalid_column_type(row.get::<_, String>(0).unwrap_err()));
#[cfg(feature = "time")]
assert!(is_invalid_column_type(
- row.get::<_, time::OffsetDateTime>(0).err().unwrap()
+ row.get::<_, time::OffsetDateTime>(0).unwrap_err()
));
assert!(is_invalid_column_type(
- row.get::<_, Option<c_int>>(0).err().unwrap()
+ row.get::<_, Option<c_int>>(0).unwrap_err()
));
// 1 is actually a text (String)
- assert!(is_invalid_column_type(
- row.get::<_, c_int>(1).err().unwrap()
- ));
+ assert!(is_invalid_column_type(row.get::<_, c_int>(1).unwrap_err()));
assert!(is_invalid_column_type(row.get::<_, i64>(1).err().unwrap()));
assert!(is_invalid_column_type(
- row.get::<_, c_double>(1).err().unwrap()
+ row.get::<_, c_double>(1).unwrap_err()
));
assert!(is_invalid_column_type(
- row.get::<_, Vec<u8>>(1).err().unwrap()
+ row.get::<_, Vec<u8>>(1).unwrap_err()
));
assert!(is_invalid_column_type(
- row.get::<_, Option<c_int>>(1).err().unwrap()
+ row.get::<_, Option<c_int>>(1).unwrap_err()
));
// 2 is actually an integer
+ assert!(is_invalid_column_type(row.get::<_, String>(2).unwrap_err()));
assert!(is_invalid_column_type(
- row.get::<_, String>(2).err().unwrap()
- ));
- assert!(is_invalid_column_type(
- row.get::<_, Vec<u8>>(2).err().unwrap()
+ row.get::<_, Vec<u8>>(2).unwrap_err()
));
assert!(is_invalid_column_type(
- row.get::<_, Option<String>>(2).err().unwrap()
+ row.get::<_, Option<String>>(2).unwrap_err()
));
// 3 is actually a float (c_double)
- assert!(is_invalid_column_type(
- row.get::<_, c_int>(3).err().unwrap()
- ));
+ assert!(is_invalid_column_type(row.get::<_, c_int>(3).unwrap_err()));
assert!(is_invalid_column_type(row.get::<_, i64>(3).err().unwrap()));
+ assert!(is_invalid_column_type(row.get::<_, String>(3).unwrap_err()));
assert!(is_invalid_column_type(
- row.get::<_, String>(3).err().unwrap()
- ));
- assert!(is_invalid_column_type(
- row.get::<_, Vec<u8>>(3).err().unwrap()
+ row.get::<_, Vec<u8>>(3).unwrap_err()
));
assert!(is_invalid_column_type(
- row.get::<_, Option<c_int>>(3).err().unwrap()
+ row.get::<_, Option<c_int>>(3).unwrap_err()
));
// 4 is actually NULL
- assert!(is_invalid_column_type(
- row.get::<_, c_int>(4).err().unwrap()
- ));
+ assert!(is_invalid_column_type(row.get::<_, c_int>(4).unwrap_err()));
assert!(is_invalid_column_type(row.get::<_, i64>(4).err().unwrap()));
assert!(is_invalid_column_type(
- row.get::<_, c_double>(4).err().unwrap()
- ));
- assert!(is_invalid_column_type(
- row.get::<_, String>(4).err().unwrap()
+ row.get::<_, c_double>(4).unwrap_err()
));
+ assert!(is_invalid_column_type(row.get::<_, String>(4).unwrap_err()));
assert!(is_invalid_column_type(
- row.get::<_, Vec<u8>>(4).err().unwrap()
+ row.get::<_, Vec<u8>>(4).unwrap_err()
));
#[cfg(feature = "time")]
assert!(is_invalid_column_type(
- row.get::<_, time::OffsetDateTime>(4).err().unwrap()
+ row.get::<_, time::OffsetDateTime>(4).unwrap_err()
));
Ok(())
}
@@ -373,7 +354,7 @@ mod test {
assert_eq!(Value::Text(String::from("text")), row.get::<_, Value>(1)?);
assert_eq!(Value::Integer(1), row.get::<_, Value>(2)?);
match row.get::<_, Value>(3)? {
- Value::Real(val) => assert!((1.5 - val).abs() < EPSILON),
+ Value::Real(val) => assert!((1.5 - val).abs() < f64::EPSILON),
x => panic!("Invalid Value {:?}", x),
}
assert_eq!(Value::Null, row.get::<_, Value>(4)?);