diff --git a/src/column.rs b/src/column.rs index 66d0e76..590a986 100644 --- a/src/column.rs +++ b/src/column.rs @@ -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> { diff --git a/src/error.rs b/src/error.rs index a1e8c45..fbdae21 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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 { 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) => { diff --git a/src/lib.rs b/src/lib.rs index 146e5da..8374e63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -568,7 +568,7 @@ impl Connection { #[inline] pub fn execute(&self, sql: &str, params: P) -> Result { 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(&self, sql: &str) -> Result { + pub(crate) fn one_column(&self, sql: &str) -> Result { 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 { let db = InnerConnection::new(db, true); diff --git a/src/pragma.rs b/src/pragma.rs index d5a2cb4..46bbde1 100644 --- a/src/pragma.rs +++ b/src/pragma.rs @@ -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); } diff --git a/src/row.rs b/src/row.rs index d8edcb1..2d25900 100644 --- a/src/row.rs +++ b/src/row.rs @@ -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: diff --git a/src/serialize.rs b/src/serialize.rs index a20a942..6852761 100644 --- a/src/serialize.rs +++ b/src/serialize.rs @@ -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, 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> { + pub fn serialize(&self, schema: DatabaseName) -> Result { let schema = schema.as_cstring()?; let mut sz = 0; let mut ptr: *mut u8 = unsafe { diff --git a/src/session.rs b/src/session.rs index c42bbd6..0169a1c 100644 --- a/src/session.rs +++ b/src/session.rs @@ -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 { diff --git a/src/statement.rs b/src/statement.rs index bdd453d..d39cc1f 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -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(); } } diff --git a/src/transaction.rs b/src/transaction.rs index e4613aa..2e90528 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -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_>(conn: &Connection, name: T) -> Result> { 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 /// diff --git a/src/types/value_ref.rs b/src/types/value_ref.rs index 07aa51b..aa062f8 100644 --- a/src/types/value_ref.rs +++ b/src/types/value_ref.rs @@ -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 { 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> { 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 { 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> { 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> { 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> { 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]> { diff --git a/src/version.rs b/src/version.rs index d70af7e..44053b7 100644 --- a/src/version.rs +++ b/src/version.rs @@ -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 {