diff --git a/libsqlite3-sys/src/error.rs b/libsqlite3-sys/src/error.rs index bd4ce7f..7228269 100644 --- a/libsqlite3-sys/src/error.rs +++ b/libsqlite3-sys/src/error.rs @@ -285,8 +285,8 @@ pub enum InitError { NullFunctionPointer, } #[cfg(feature = "loadable_extension")] -impl ::std::fmt::Display for InitError { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { +impl fmt::Display for InitError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Self::VersionMismatch { compile_time, diff --git a/src/blob/pos_io.rs b/src/blob/pos_io.rs index c69e6d0..0367980 100644 --- a/src/blob/pos_io.rs +++ b/src/blob/pos_io.rs @@ -208,21 +208,21 @@ mod test { blob.seek(std::io::SeekFrom::Start(1)).unwrap(); let one2ten: [u8; 10] = [1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - blob.write_at(&one2ten, 0).unwrap(); + blob.write_at(&one2ten, 0)?; let mut s = [0u8; 10]; - blob.read_at_exact(&mut s, 0).unwrap(); + blob.read_at_exact(&mut s, 0)?; assert_eq!(&s, &one2ten, "write should go through"); blob.read_at_exact(&mut s, 1).unwrap_err(); - blob.read_at_exact(&mut s, 0).unwrap(); + blob.read_at_exact(&mut s, 0)?; assert_eq!(&s, &one2ten, "should be unchanged"); let mut fives = [0u8; 5]; - blob.read_at_exact(&mut fives, 0).unwrap(); + blob.read_at_exact(&mut fives, 0)?; assert_eq!(&fives, &[1u8, 2, 3, 4, 5]); - blob.read_at_exact(&mut fives, 5).unwrap(); + blob.read_at_exact(&mut fives, 5)?; assert_eq!(&fives, &[6u8, 7, 8, 9, 10]); blob.read_at_exact(&mut fives, 7).unwrap_err(); blob.read_at_exact(&mut fives, 12).unwrap_err(); @@ -233,12 +233,12 @@ mod test { .unwrap_err(); // zero length writes are fine if in bounds - blob.read_at_exact(&mut [], 10).unwrap(); - blob.read_at_exact(&mut [], 0).unwrap(); - blob.read_at_exact(&mut [], 5).unwrap(); + blob.read_at_exact(&mut [], 10)?; + blob.read_at_exact(&mut [], 0)?; + blob.read_at_exact(&mut [], 5)?; - blob.write_all_at(&[16, 17, 18, 19, 20], 5).unwrap(); - blob.read_at_exact(&mut s, 0).unwrap(); + blob.write_all_at(&[16, 17, 18, 19, 20], 5)?; + blob.read_at_exact(&mut s, 0)?; assert_eq!(&s, &[1u8, 2, 3, 4, 5, 16, 17, 18, 19, 20]); blob.write_at(&[100, 99, 98, 97, 96], 6).unwrap_err(); @@ -247,19 +247,19 @@ mod test { blob.write_at(&[100, 99, 98, 97, 96], i32::MAX as usize + 1) .unwrap_err(); - blob.read_at_exact(&mut s, 0).unwrap(); + blob.read_at_exact(&mut s, 0)?; assert_eq!(&s, &[1u8, 2, 3, 4, 5, 16, 17, 18, 19, 20]); let mut s2: [std::mem::MaybeUninit; 10] = [std::mem::MaybeUninit::uninit(); 10]; { - let read = blob.raw_read_at_exact(&mut s2, 0).unwrap(); + let read = blob.raw_read_at_exact(&mut s2, 0)?; assert_eq!(read, &s); assert!(std::ptr::eq(read.as_ptr(), s2.as_ptr().cast())); } let mut empty = []; assert!(std::ptr::eq( - blob.raw_read_at_exact(&mut empty, 0).unwrap().as_ptr(), + blob.raw_read_at_exact(&mut empty, 0)?.as_ptr(), empty.as_ptr().cast(), )); blob.raw_read_at_exact(&mut s2, 5).unwrap_err(); diff --git a/src/error.rs b/src/error.rs index 3435081..a256797 100644 --- a/src/error.rs +++ b/src/error.rs @@ -452,7 +452,7 @@ pub unsafe fn error_with_offset(db: *mut ffi::sqlite3, code: c_int, sql: &str) - } pub fn check(code: c_int) -> Result<()> { - if code != crate::ffi::SQLITE_OK { + if code != ffi::SQLITE_OK { Err(error_from_sqlite_code(code, None)) } else { Ok(()) diff --git a/src/functions.rs b/src/functions.rs index d9b36e8..4aef3f3 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -368,7 +368,7 @@ bitflags::bitflags! { /// and [Function Flags](https://sqlite.org/c3ref/c_deterministic.html) for details. #[derive(Clone, Copy, Debug)] #[repr(C)] - pub struct FunctionFlags: ::std::os::raw::c_int { + pub struct FunctionFlags: c_int { /// Specifies UTF-8 as the text encoding this SQL function prefers for its parameters. const SQLITE_UTF8 = ffi::SQLITE_UTF8; /// Specifies UTF-16 using little-endian byte order as the text encoding this SQL function prefers for its parameters. @@ -693,7 +693,7 @@ unsafe extern "C" fn call_boxed_step( D: Aggregate, T: SqlFnOutput, { - let Some(pac) = aggregate_context(ctx, std::mem::size_of::<*mut A>()) else { + let Some(pac) = aggregate_context(ctx, size_of::<*mut A>()) else { ffi::sqlite3_result_error_nomem(ctx); return; }; @@ -739,7 +739,7 @@ unsafe extern "C" fn call_boxed_inverse( W: WindowAggregate, T: SqlFnOutput, { - let Some(pac) = aggregate_context(ctx, std::mem::size_of::<*mut A>()) else { + let Some(pac) = aggregate_context(ctx, size_of::<*mut A>()) else { ffi::sqlite3_result_error_nomem(ctx); return; }; diff --git a/src/hooks/mod.rs b/src/hooks/mod.rs index c7ab248..be49bc1 100644 --- a/src/hooks/mod.rs +++ b/src/hooks/mod.rs @@ -869,8 +869,7 @@ mod test { use super::{AuthAction, AuthContext, Authorization}; let db = Connection::open_in_memory()?; - db.execute_batch("CREATE TABLE foo (public TEXT, private TEXT)") - .unwrap(); + db.execute_batch("CREATE TABLE foo (public TEXT, private TEXT)")?; let authorizer = move |ctx: AuthContext<'_>| match ctx.action { AuthAction::Read { @@ -885,18 +884,16 @@ mod test { db.authorizer(Some(authorizer)); db.execute_batch( "BEGIN TRANSACTION; INSERT INTO foo VALUES ('pub txt', 'priv txt'); COMMIT;", - ) - .unwrap(); + )?; db.query_row_and_then("SELECT * FROM foo", [], |row| -> Result<()> { assert_eq!(row.get::<_, String>("public")?, "pub txt"); assert!(row.get::<_, Option>("private")?.is_none()); Ok(()) - }) - .unwrap(); + })?; db.execute_batch("DROP TABLE foo").unwrap_err(); db.authorizer(None::) -> Authorization>); - db.execute_batch("PRAGMA user_version=1").unwrap(); // Disallowed by first authorizer, but it's now removed. + db.execute_batch("PRAGMA user_version=1")?; // Disallowed by first authorizer, but it's now removed. Ok(()) } diff --git a/src/inner_connection.rs b/src/inner_connection.rs index 4618054..5615807 100644 --- a/src/inner_connection.rs +++ b/src/inner_connection.rs @@ -34,7 +34,7 @@ pub struct InnerConnection { #[cfg(feature = "hooks")] pub authorizer: Option, #[cfg(feature = "preupdate_hook")] - pub free_preupdate_hook: Option, + pub free_preupdate_hook: Option, owned: bool, } diff --git a/src/lib.rs b/src/lib.rs index 911f3f4..f47425c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,7 +46,7 @@ //! })?; //! //! for person in person_iter { -//! println!("Found person {:?}", person.unwrap()); +//! println!("Found person {:?}", person?); //! } //! Ok(()) //! } @@ -1169,7 +1169,7 @@ bitflags::bitflags! { /// some discussion about these flags. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] #[repr(C)] - pub struct OpenFlags: ::std::os::raw::c_int { + pub struct OpenFlags: c_int { /// The database is opened in read-only mode. /// If the database does not already exist, an error is returned. const SQLITE_OPEN_READ_ONLY = ffi::SQLITE_OPEN_READONLY; @@ -2272,11 +2272,11 @@ mod test { #[cfg(feature = "modern_sqlite")] fn test_db_name() -> Result<()> { let db = Connection::open_in_memory()?; - assert_eq!(db.db_name(0).unwrap(), "main"); - assert_eq!(db.db_name(1).unwrap(), "temp"); + assert_eq!(db.db_name(0)?, "main"); + assert_eq!(db.db_name(1)?, "temp"); assert_eq!(db.db_name(2), Err(Error::InvalidDatabaseIndex(2))); db.execute_batch("ATTACH DATABASE ':memory:' AS xyz;")?; - assert_eq!(db.db_name(2).unwrap(), "xyz"); + assert_eq!(db.db_name(2)?, "xyz"); Ok(()) } diff --git a/src/session.rs b/src/session.rs index 855441c..180f588 100644 --- a/src/session.rs +++ b/src/session.rs @@ -333,7 +333,7 @@ impl ChangesetIter<'_> { } impl FallibleStreamingIterator for ChangesetIter<'_> { - type Error = crate::error::Error; + type Error = Error; type Item = ChangesetItem; #[inline] diff --git a/src/statement.rs b/src/statement.rs index f7b1e95..b11c31b 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -1285,9 +1285,9 @@ mod test { let conn = Connection::open_in_memory()?; let mut stmt = conn.prepare("")?; assert_eq!(0, stmt.column_count()); - stmt.parameter_index("test").unwrap(); + stmt.parameter_index("test")?; stmt.step().unwrap_err(); - stmt.reset().unwrap(); // SQLITE_OMIT_AUTORESET = false + stmt.reset()?; // SQLITE_OMIT_AUTORESET = false stmt.execute([]).unwrap_err(); Ok(()) } diff --git a/src/types/chrono.rs b/src/types/chrono.rs index 774508a..65ec84b 100644 --- a/src/types/chrono.rs +++ b/src/types/chrono.rs @@ -285,13 +285,13 @@ mod test { fn test_sqlite_functions() -> Result<()> { let db = checked_memory_handle()?; let result: Result = db.one_column("SELECT CURRENT_TIME"); - result.unwrap(); + result?; let result: Result = db.one_column("SELECT CURRENT_DATE"); - result.unwrap(); + result?; let result: Result = db.one_column("SELECT CURRENT_TIMESTAMP"); - result.unwrap(); + result?; let result: Result> = db.one_column("SELECT CURRENT_TIMESTAMP"); - result.unwrap(); + result?; Ok(()) } @@ -299,7 +299,7 @@ mod test { fn test_naive_date_time_param() -> Result<()> { let db = checked_memory_handle()?; let result: Result = db.query_row("SELECT 1 WHERE ?1 BETWEEN datetime('now', '-1 minute') AND datetime('now', '+1 minute')", [Utc::now().naive_utc()], |r| r.get(0)); - result.unwrap(); + result?; Ok(()) } @@ -307,7 +307,7 @@ mod test { fn test_date_time_param() -> Result<()> { let db = checked_memory_handle()?; let result: Result = db.query_row("SELECT 1 WHERE ?1 BETWEEN datetime('now', '-1 minute') AND datetime('now', '+1 minute')", [Utc::now()], |r| r.get(0)); - result.unwrap(); + result?; Ok(()) } diff --git a/src/types/time.rs b/src/types/time.rs index ed44ff8..efae782 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -1,8 +1,8 @@ //! Convert formats 1-10 in [Time Values](https://sqlite.org/lang_datefunc.html#time_values) to time types. -//! [`ToSql`] and [`FromSql`] implementation for [`time::OffsetDateTime`]. -//! [`ToSql`] and [`FromSql`] implementation for [`time::PrimitiveDateTime`]. -//! [`ToSql`] and [`FromSql`] implementation for [`time::Date`]. -//! [`ToSql`] and [`FromSql`] implementation for [`time::Time`]. +//! [`ToSql`] and [`FromSql`] implementation for [`OffsetDateTime`]. +//! [`ToSql`] and [`FromSql`] implementation for [`PrimitiveDateTime`]. +//! [`ToSql`] and [`FromSql`] implementation for [`Date`]. +//! [`ToSql`] and [`FromSql`] implementation for [`Time`]. //! Time Strings in: //! - Format 2: "YYYY-MM-DD HH:MM" //! - Format 5: "YYYY-MM-DDTHH:MM" @@ -362,12 +362,10 @@ mod test { #[test] fn test_sqlite_functions() -> Result<()> { let db = checked_memory_handle()?; - db.one_column::