mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-10-31 13:58:55 +08:00 
			
		
		
		
	Fix some clipy warnings
This commit is contained in:
		| @@ -90,6 +90,8 @@ impl Statement<'_> { | ||||
|     /// Returns an `Error::InvalidColumnIndex` if `idx` is outside the valid | ||||
|     /// column range for this row. | ||||
|     /// | ||||
|     /// # Panics | ||||
|     /// | ||||
|     /// Panics when column name is not valid UTF-8. | ||||
|     #[inline] | ||||
|     pub fn column_name(&self, col: usize) -> Result<&str> { | ||||
|   | ||||
| @@ -367,6 +367,7 @@ impl error::Error for Error { | ||||
| impl Error { | ||||
|     /// Returns the underlying SQLite error if this is [`Error::SqliteFailure`]. | ||||
|     #[inline] | ||||
|     #[must_use] | ||||
|     pub fn sqlite_error(&self) -> Option<&ffi::Error> { | ||||
|         match self { | ||||
|             Self::SqliteFailure(error, _) => Some(error), | ||||
| @@ -377,6 +378,7 @@ impl Error { | ||||
|     /// Returns the underlying SQLite error code if this is | ||||
|     /// [`Error::SqliteFailure`]. | ||||
|     #[inline] | ||||
|     #[must_use] | ||||
|     pub fn sqlite_error_code(&self) -> Option<ffi::ErrorCode> { | ||||
|         self.sqlite_error().map(|error| error.code) | ||||
|     } | ||||
| @@ -439,10 +441,7 @@ pub fn check(code: c_int) -> Result<()> { | ||||
| /// Transform Rust error to SQLite error (message and code). | ||||
| /// # Safety | ||||
| /// This function is unsafe because it uses raw pointer | ||||
| pub unsafe fn to_sqlite_error( | ||||
|     e: &Error, | ||||
|     err_msg: *mut *mut std::os::raw::c_char, | ||||
| ) -> std::os::raw::c_int { | ||||
| pub unsafe fn to_sqlite_error(e: &Error, err_msg: *mut *mut std::os::raw::c_char) -> c_int { | ||||
|     use crate::util::alloc; | ||||
|     match e { | ||||
|         Error::SqliteFailure(err, s) => { | ||||
|   | ||||
| @@ -568,7 +568,7 @@ impl Connection { | ||||
|     #[inline] | ||||
|     pub fn execute<P: Params>(&self, sql: &str, params: P) -> Result<usize> { | ||||
|         self.prepare(sql) | ||||
|             .and_then(|mut stmt| stmt.check_no_tail().and_then(|_| stmt.execute(params))) | ||||
|             .and_then(|mut stmt| stmt.check_no_tail().and_then(|()| stmt.execute(params))) | ||||
|     } | ||||
|  | ||||
|     /// Returns the path to the database file, if one exists and is known. | ||||
| @@ -651,7 +651,7 @@ impl Connection { | ||||
|  | ||||
|     // https://sqlite.org/tclsqlite.html#onecolumn | ||||
|     #[cfg(test)] | ||||
|     pub(crate) fn one_column<T: crate::types::FromSql>(&self, sql: &str) -> Result<T> { | ||||
|     pub(crate) fn one_column<T: types::FromSql>(&self, sql: &str) -> Result<T> { | ||||
|         self.query_row(sql, [], |r| r.get(0)) | ||||
|     } | ||||
|  | ||||
| @@ -912,7 +912,7 @@ impl Connection { | ||||
|     /// This function is unsafe because improper use may impact the Connection. | ||||
|     /// In particular, it should only be called on connections created | ||||
|     /// and owned by the caller, e.g. as a result of calling | ||||
|     /// ffi::sqlite3_open(). | ||||
|     /// `ffi::sqlite3_open`(). | ||||
|     #[inline] | ||||
|     pub unsafe fn from_handle_owned(db: *mut ffi::sqlite3) -> Result<Connection> { | ||||
|         let db = InnerConnection::new(db, true); | ||||
|   | ||||
| @@ -384,7 +384,6 @@ mod test { | ||||
|         let mut rows = table_info.query(["sqlite_master"])?; | ||||
|  | ||||
|         while let Some(row) = rows.next()? { | ||||
|             let row = row; | ||||
|             let column: String = row.get(1)?; | ||||
|             columns.push(column); | ||||
|         } | ||||
|   | ||||
| @@ -29,8 +29,8 @@ impl<'stmt> Rows<'stmt> { | ||||
|     /// This interface is not compatible with Rust's `Iterator` trait, because | ||||
|     /// the lifetime of the returned row is tied to the lifetime of `self`. | ||||
|     /// This is a fallible "streaming iterator". For a more natural interface, | ||||
|     /// consider using [`query_map`](crate::Statement::query_map) or | ||||
|     /// [`query_and_then`](crate::Statement::query_and_then) instead, which | ||||
|     /// consider using [`query_map`](Statement::query_map) or | ||||
|     /// [`query_and_then`](Statement::query_and_then) instead, which | ||||
|     /// return types that implement `Iterator`. | ||||
|     #[allow(clippy::should_implement_trait)] // cannot implement Iterator | ||||
|     #[inline] | ||||
| @@ -247,7 +247,7 @@ pub struct Row<'stmt> { | ||||
| impl<'stmt> Row<'stmt> { | ||||
|     /// Get the value of a particular column of the result row. | ||||
|     /// | ||||
|     /// ## Failure | ||||
|     /// # Panics | ||||
|     /// | ||||
|     /// Panics if calling [`row.get(idx)`](Row::get) would return an error, | ||||
|     /// including: | ||||
| @@ -330,7 +330,7 @@ impl<'stmt> Row<'stmt> { | ||||
|     /// it can be difficult to use, and most callers will be better served by | ||||
|     /// [`get`](Row::get) or [`get_unwrap`](Row::get_unwrap). | ||||
|     /// | ||||
|     /// ## Failure | ||||
|     /// # Panics | ||||
|     /// | ||||
|     /// Panics if calling [`row.get_ref(idx)`](Row::get_ref) would return an | ||||
|     /// error, including: | ||||
|   | ||||
| @@ -22,8 +22,9 @@ pub struct OwnedData { | ||||
| } | ||||
|  | ||||
| impl OwnedData { | ||||
|     /// SAFETY: Caller must be certain that `ptr` is allocated by | ||||
|     /// `sqlite3_malloc`. | ||||
|     /// # Safety | ||||
|     /// | ||||
|     /// Caller must be certain that `ptr` is allocated by `sqlite3_malloc`. | ||||
|     pub unsafe fn from_raw_nonnull(ptr: NonNull<u8>, sz: usize) -> Self { | ||||
|         Self { ptr, sz } | ||||
|     } | ||||
| @@ -65,7 +66,7 @@ impl<'conn> Deref for Data<'conn> { | ||||
|  | ||||
| impl Connection { | ||||
|     /// Serialize a database. | ||||
|     pub fn serialize<'conn>(&'conn self, schema: DatabaseName<'_>) -> Result<Data<'conn>> { | ||||
|     pub fn serialize(&self, schema: DatabaseName) -> Result<Data> { | ||||
|         let schema = schema.as_cstring()?; | ||||
|         let mut sz = 0; | ||||
|         let mut ptr: *mut u8 = unsafe { | ||||
|   | ||||
| @@ -405,7 +405,7 @@ impl Drop for ChangesetIter<'_> { | ||||
| } | ||||
|  | ||||
| /// An item passed to a conflict-handler by | ||||
| /// [`Connection::apply`](crate::Connection::apply), or an item generated by | ||||
| /// [`Connection::apply`](Connection::apply), or an item generated by | ||||
| /// [`ChangesetIter::next`](ChangesetIter::next). | ||||
| // TODO enum ? Delete, Insert, Update, ... | ||||
| pub struct ChangesetItem { | ||||
|   | ||||
| @@ -435,6 +435,10 @@ impl Statement<'_> { | ||||
|     /// | ||||
|     /// Will return `None` if the column index is out of bounds or if the | ||||
|     /// parameter is positional. | ||||
|     /// | ||||
|     /// # Panics | ||||
|     /// | ||||
|     /// Panics when parameter name is not valid UTF-8. | ||||
|     #[inline] | ||||
|     pub fn parameter_name(&self, index: usize) -> Option<&'_ str> { | ||||
|         self.stmt.bind_parameter_name(index as i32).map(|name| { | ||||
| @@ -450,7 +454,7 @@ impl Statement<'_> { | ||||
|     { | ||||
|         let expected = self.stmt.bind_parameter_count(); | ||||
|         let mut index = 0; | ||||
|         for p in params.into_iter() { | ||||
|         for p in params { | ||||
|             index += 1; // The leftmost SQL parameter has an index of 1. | ||||
|             if index > expected { | ||||
|                 break; | ||||
| @@ -744,7 +748,7 @@ impl Statement<'_> { | ||||
|  | ||||
|     /// Reset all bindings | ||||
|     pub fn clear_bindings(&mut self) { | ||||
|         self.stmt.clear_bindings() | ||||
|         self.stmt.clear_bindings(); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -122,7 +122,7 @@ impl Transaction<'_> { | ||||
|             TransactionBehavior::Immediate => "BEGIN IMMEDIATE", | ||||
|             TransactionBehavior::Exclusive => "BEGIN EXCLUSIVE", | ||||
|         }; | ||||
|         conn.execute_batch(query).map(move |_| Transaction { | ||||
|         conn.execute_batch(query).map(move |()| Transaction { | ||||
|             conn, | ||||
|             drop_behavior: DropBehavior::Rollback, | ||||
|         }) | ||||
| @@ -251,7 +251,7 @@ impl Savepoint<'_> { | ||||
|     fn with_name_<T: Into<String>>(conn: &Connection, name: T) -> Result<Savepoint<'_>> { | ||||
|         let name = name.into(); | ||||
|         conn.execute_batch(&format!("SAVEPOINT {name}")) | ||||
|             .map(|_| Savepoint { | ||||
|             .map(|()| Savepoint { | ||||
|                 conn, | ||||
|                 name, | ||||
|                 drop_behavior: DropBehavior::Rollback, | ||||
| @@ -346,8 +346,8 @@ impl Savepoint<'_> { | ||||
|         match self.drop_behavior() { | ||||
|             DropBehavior::Commit => self | ||||
|                 .commit_() | ||||
|                 .or_else(|_| self.rollback().and_then(|_| self.commit_())), | ||||
|             DropBehavior::Rollback => self.rollback().and_then(|_| self.commit_()), | ||||
|                 .or_else(|_| self.rollback().and_then(|()| self.commit_())), | ||||
|             DropBehavior::Rollback => self.rollback().and_then(|()| self.commit_()), | ||||
|             DropBehavior::Ignore => Ok(()), | ||||
|             DropBehavior::Panic => panic!("Savepoint dropped unexpectedly."), | ||||
|         } | ||||
| @@ -471,8 +471,7 @@ impl Connection { | ||||
|     /// | ||||
|     /// The savepoint defaults to rolling back when it is dropped. If you want | ||||
|     /// the savepoint to commit, you must call [`commit`](Savepoint::commit) or | ||||
|     /// [`set_drop_behavior(DropBehavior::Commit)`](Savepoint:: | ||||
|     /// set_drop_behavior). | ||||
|     /// [`set_drop_behavior(DropBehavior::Commit)`](Savepoint::set_drop_behavior). | ||||
|     /// | ||||
|     /// ## Example | ||||
|     /// | ||||
|   | ||||
| @@ -36,8 +36,7 @@ impl ValueRef<'_> { | ||||
|  | ||||
| impl<'a> ValueRef<'a> { | ||||
|     /// If `self` is case `Integer`, returns the integral value. Otherwise, | ||||
|     /// returns [`Err(Error::InvalidColumnType)`](crate::Error:: | ||||
|     /// InvalidColumnType). | ||||
|     /// returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType). | ||||
|     #[inline] | ||||
|     pub fn as_i64(&self) -> FromSqlResult<i64> { | ||||
|         match *self { | ||||
| @@ -48,8 +47,7 @@ impl<'a> ValueRef<'a> { | ||||
|  | ||||
|     /// If `self` is case `Null` returns None. | ||||
|     /// If `self` is case `Integer`, returns the integral value. | ||||
|     /// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error:: | ||||
|     /// InvalidColumnType). | ||||
|     /// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType). | ||||
|     #[inline] | ||||
|     pub fn as_i64_or_null(&self) -> FromSqlResult<Option<i64>> { | ||||
|         match *self { | ||||
| @@ -60,8 +58,7 @@ impl<'a> ValueRef<'a> { | ||||
|     } | ||||
|  | ||||
|     /// If `self` is case `Real`, returns the floating point value. Otherwise, | ||||
|     /// returns [`Err(Error::InvalidColumnType)`](crate::Error:: | ||||
|     /// InvalidColumnType). | ||||
|     /// returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType). | ||||
|     #[inline] | ||||
|     pub fn as_f64(&self) -> FromSqlResult<f64> { | ||||
|         match *self { | ||||
| @@ -72,8 +69,7 @@ impl<'a> ValueRef<'a> { | ||||
|  | ||||
|     /// If `self` is case `Null` returns None. | ||||
|     /// If `self` is case `Real`, returns the floating point value. | ||||
|     /// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error:: | ||||
|     /// InvalidColumnType). | ||||
|     /// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType). | ||||
|     #[inline] | ||||
|     pub fn as_f64_or_null(&self) -> FromSqlResult<Option<f64>> { | ||||
|         match *self { | ||||
| @@ -97,8 +93,7 @@ impl<'a> ValueRef<'a> { | ||||
|  | ||||
|     /// If `self` is case `Null` returns None. | ||||
|     /// If `self` is case `Text`, returns the string value. | ||||
|     /// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error:: | ||||
|     /// InvalidColumnType). | ||||
|     /// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType). | ||||
|     #[inline] | ||||
|     pub fn as_str_or_null(&self) -> FromSqlResult<Option<&'a str>> { | ||||
|         match *self { | ||||
| @@ -122,8 +117,7 @@ impl<'a> ValueRef<'a> { | ||||
|  | ||||
|     /// If `self` is case `Null` returns None. | ||||
|     /// If `self` is case `Blob`, returns the byte slice. | ||||
|     /// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error:: | ||||
|     /// InvalidColumnType). | ||||
|     /// Otherwise returns [`Err(Error::InvalidColumnType)`](crate::Error::InvalidColumnType). | ||||
|     #[inline] | ||||
|     pub fn as_blob_or_null(&self) -> FromSqlResult<Option<&'a [u8]>> { | ||||
|         match *self { | ||||
| @@ -133,7 +127,7 @@ impl<'a> ValueRef<'a> { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /// Returns the byte slice that makes up this ValueRef if it's either | ||||
|     /// Returns the byte slice that makes up this `ValueRef` if it's either | ||||
|     /// [`ValueRef::Blob`] or [`ValueRef::Text`]. | ||||
|     #[inline] | ||||
|     pub fn as_bytes(&self) -> FromSqlResult<&'a [u8]> { | ||||
|   | ||||
| @@ -14,6 +14,10 @@ pub fn version_number() -> i32 { | ||||
| /// 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). | ||||
| /// | ||||
| /// # Panics | ||||
| /// | ||||
| /// Panics when version is not valid UTF-8. | ||||
| #[inline] | ||||
| #[must_use] | ||||
| pub fn version() -> &'static str { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user