Browse Source

Fix clippy nits.

Kestrel 9 months ago
parent
commit
897406216b
4 changed files with 22 additions and 21 deletions
  1. 16 15
      microrm/src/db.rs
  2. 2 2
      microrm/src/query.rs
  3. 3 3
      microrm/src/schema.rs
  4. 1 1
      microrm/src/schema/datum/datum_common.rs

+ 16 - 15
microrm/src/db.rs

@@ -25,6 +25,8 @@ struct ConnectionData {
     stmts: HashMap<u64, Statement>,
 }
 
+unsafe impl Send for ConnectionData {}
+
 pub(crate) trait PreparedKey {
     fn into_u64(self) -> u64;
 }
@@ -98,7 +100,7 @@ impl Connection {
             if rcode != sq::SQLITE_OK {
                 let e = Error::Sqlite {
                     code: rcode,
-                    msg: if err == std::ptr::null_mut() {
+                    msg: if err.is_null() {
                         CStr::from_ptr(sq::sqlite3_errstr(rcode))
                     } else {
                         CStr::from_ptr(err)
@@ -107,7 +109,7 @@ impl Connection {
                     .to_string(),
                     sql: Some(sql.as_ref().into()),
                 };
-                if err != std::ptr::null_mut() {
+                if !err.is_null() {
                     sq::sqlite3_free(err.cast());
                 }
                 return Err(e);
@@ -146,7 +148,7 @@ impl Connection {
                     )?;
                 };
 
-                if stmt == std::ptr::null_mut() {
+                if stmt.is_null() {
                     return Err(Error::InternalError(
                         "sqlite3_prepare_v2 returned a NULL stmt",
                     ));
@@ -161,9 +163,8 @@ impl Connection {
     }
 }
 
-unsafe impl Send for Connection {}
-
 struct Statement {
+    #[allow(unused)]
     sqlite: *mut sq::sqlite3,
     stmt: *mut sq::sqlite3_stmt,
 }
@@ -299,19 +300,19 @@ pub trait Bindable {
     fn bind_to(&self, ctx: &StatementContext, index: i32) -> DBResult<()>;
 }
 
-impl<'a> Bindable for () {
+impl Bindable for () {
     fn bind_to(&self, ctx: &StatementContext, index: i32) -> DBResult<()> {
         unsafe { check_rcode(None, sq::sqlite3_bind_null(ctx.stmt.stmt, index)) }
     }
 }
 
-impl<'a> Bindable for i64 {
+impl Bindable for i64 {
     fn bind_to(&self, ctx: &StatementContext, index: i32) -> DBResult<()> {
         unsafe { check_rcode(None, sq::sqlite3_bind_int64(ctx.stmt.stmt, index, *self)) }
     }
 }
 
-impl<'a> Bindable for usize {
+impl Bindable for usize {
     fn bind_to(&self, ctx: &StatementContext, index: i32) -> DBResult<()> {
         (*self as i64).bind_to(ctx, index)
     }
@@ -394,14 +395,14 @@ impl Readable for Vec<u8> {
             let ptr = sq::sqlite3_column_blob(sr.stmt.stmt, index);
             let len = sq::sqlite3_column_bytes(sr.stmt.stmt, index);
 
-            if len == 0 {
-                Ok(vec![])
-            } else if len > 0 {
-                Ok(std::slice::from_raw_parts(ptr.cast(), len as usize).to_vec())
-            } else {
-                Err(Error::InternalError(
+            match len.cmp(&0) {
+                std::cmp::Ordering::Equal => Ok(vec![]),
+                std::cmp::Ordering::Less => Err(Error::InternalError(
                     "negative length returned from sqlite3_column_bytes",
-                ))
+                )),
+                std::cmp::Ordering::Greater => {
+                    Ok(std::slice::from_raw_parts(ptr.cast(), len as usize).to_vec())
+                }
             }
         }
     }

+ 2 - 2
microrm/src/query.rs

@@ -261,7 +261,7 @@ pub trait AssocInterface: 'static {
                     remote_field = an.remote_field
                 )
             },
-            |mut ctx| {
+            |ctx| {
                 ctx.bind(1, adata.local_id)?;
                 ctx.bind(2, remote_id.into_raw())?;
 
@@ -288,7 +288,7 @@ pub trait AssocInterface: 'static {
                     remote_field = an.remote_field
                 )
             },
-            |mut ctx| {
+            |ctx| {
                 ctx.bind(1, adata.local_id)?;
                 ctx.bind(2, remote_id.into_raw())?;
 

+ 3 - 3
microrm/src/schema.rs

@@ -190,7 +190,7 @@ impl<T: Entity> Datum for AssocMap<T> {
         unreachable!()
     }
 
-    fn build_from(adata: AssocData, _stmt: &mut StatementRow, index: &mut i32) -> DBResult<Self>
+    fn build_from(adata: AssocData, _stmt: &mut StatementRow, _index: &mut i32) -> DBResult<Self>
     where
         Self: Sized,
     {
@@ -266,7 +266,7 @@ impl<R: Relation> Datum for AssocDomain<R> {
         unreachable!()
     }
 
-    fn build_from(adata: AssocData, _stmt: &mut StatementRow, index: &mut i32) -> DBResult<Self>
+    fn build_from(adata: AssocData, _stmt: &mut StatementRow, _index: &mut i32) -> DBResult<Self>
     where
         Self: Sized,
     {
@@ -342,7 +342,7 @@ impl<R: Relation> Datum for AssocRange<R> {
         unreachable!()
     }
 
-    fn build_from(adata: AssocData, _stmt: &mut StatementRow, index: &mut i32) -> DBResult<Self>
+    fn build_from(adata: AssocData, _stmt: &mut StatementRow, _index: &mut i32) -> DBResult<Self>
     where
         Self: Sized,
     {

+ 1 - 1
microrm/src/schema/datum/datum_common.rs

@@ -19,7 +19,7 @@ impl Datum for time::OffsetDateTime {
         Self: Sized,
     {
         let unix = i64::build_from(adata, stmt, index)?;
-        Ok(Self::from_unix_timestamp(unix).map_err(|e| Error::UnknownValue(e.to_string()))?)
+        Self::from_unix_timestamp(unix).map_err(|e| Error::UnknownValue(e.to_string()))
     }
 }