From a25f476734dd3588637ab5a35fb4e07260cab319 Mon Sep 17 00:00:00 2001 From: Conrad Dean Date: Sat, 20 Jul 2019 13:22:46 -0400 Subject: [PATCH] remove wrapper types that seem unnecessary, and wrap the result of a fn with a Result as the compiler told me --- db/src/cache.rs | 4 ++-- db/src/db.rs | 24 ++++++++---------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/db/src/cache.rs b/db/src/cache.rs index 0689d266..c5d80e70 100644 --- a/db/src/cache.rs +++ b/db/src/cache.rs @@ -215,7 +215,7 @@ pub struct AevRows<'conn, F> { /// for now it's convenient to avoid error handling. impl<'conn, F> Iterator for AevRows<'conn, F> where - F: FnMut(&rusqlite::Row) -> Aev, + F: FnMut(&rusqlite::Row) -> Result, { type Item = Aev; fn next(&mut self) -> Option { @@ -1075,7 +1075,7 @@ impl AttributeCaches { replacing: bool, ) -> Result<()> { let mut aev_factory = AevFactory::new(); - let rows = statement.query_map(&args, |row| aev_factory.row_to_aev(row))?; + let rows = statement.query_map(&args, |row| Ok(aev_factory.row_to_aev(row)))?; let aevs = AevRows { rows: rows }; self.accumulate_into_cache( None, diff --git a/db/src/db.rs b/db/src/db.rs index 0518a7e9..9646be0b 100644 --- a/db/src/db.rs +++ b/db/src/db.rs @@ -456,23 +456,15 @@ impl TypedSQLValue for TypedValue { /// Return the corresponding SQLite `value` and `value_type_tag` pair. fn to_sql_value_pair<'a>(&'a self) -> (ToSqlOutput<'a>, i32) { match self { - &TypedValue::Ref(x) => (rusqlite::types::Value::Integer(x).into(), 0), - &TypedValue::Boolean(x) => ( - rusqlite::types::Value::Integer(if x { 1 } else { 0 }).into(), - 1, - ), - &TypedValue::Instant(x) => (rusqlite::types::Value::Integer(x.to_micros()).into(), 4), + &TypedValue::Ref(x) => (x.into(), 0), + &TypedValue::Boolean(x) => ((if x { 1 } else { 0 }).into(), 1), + &TypedValue::Instant(x) => (x.to_micros().into(), 4), // SQLite distinguishes integral from decimal types, allowing long and double to share a tag. - &TypedValue::Long(x) => (rusqlite::types::Value::Integer(x).into(), 5), - &TypedValue::Double(x) => (rusqlite::types::Value::Real(x.into_inner()).into(), 5), - &TypedValue::String(ref x) => (rusqlite::types::ValueRef::Text(x.as_str()).into(), 10), - &TypedValue::Uuid(ref u) => ( - rusqlite::types::Value::Blob(u.as_bytes().to_vec()).into(), - 11, - ), - &TypedValue::Keyword(ref x) => { - (rusqlite::types::ValueRef::Text(&x.to_string()).into(), 13) - } + &TypedValue::Long(x) => (x.into(), 5), + &TypedValue::Double(x) => (x.into_inner().into(), 5), + &TypedValue::String(ref x) => (x.as_str().into(), 10), + &TypedValue::Uuid(ref u) => (u.as_bytes().to_vec().into(), 11), + &TypedValue::Keyword(ref x) => (x.to_string().into(), 13), } }