diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index 2392c3d..e25dc4d 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -179,9 +179,11 @@ mod build_bundled { if cfg!(feature = "bundled-sqlcipher-vendored-openssl") { cfg.include(std::env::var("DEP_OPENSSL_INCLUDE").unwrap()); - // cargo will resolve downstream to the static lib in openssl-sys + // cargo will resolve downstream to the static lib in + // openssl-sys } else if is_windows { - // Windows without `-vendored-openssl` takes this to link against a prebuilt OpenSSL lib + // Windows without `-vendored-openssl` takes this to link against a prebuilt + // OpenSSL lib cfg.include(inc_dir.to_string_lossy().as_ref()); let lib = lib_dir.join("libcrypto.lib"); cfg.flag(lib.to_string_lossy().as_ref()); diff --git a/src/collation.rs b/src/collation.rs index 7e6673a..7a24ad7 100644 --- a/src/collation.rs +++ b/src/collation.rs @@ -16,9 +16,9 @@ unsafe extern "C" fn free_boxed_value(p: *mut c_void) { impl Connection { /// Add or modify a collation. #[inline] - pub fn create_collation<'c, C>(&'c self, collation_name: &str, x_compare: C) -> Result<()> + pub fn create_collation(&self, collation_name: &str, x_compare: C) -> Result<()> where - C: Fn(&str, &str) -> Ordering + Send + UnwindSafe + 'c, + C: Fn(&str, &str) -> Ordering + Send + UnwindSafe + 'static, { self.db .borrow_mut() @@ -42,9 +42,9 @@ impl Connection { } impl InnerConnection { - fn create_collation<'c, C>(&'c mut self, collation_name: &str, x_compare: C) -> Result<()> + fn create_collation(&mut self, collation_name: &str, x_compare: C) -> Result<()> where - C: Fn(&str, &str) -> Ordering + Send + UnwindSafe + 'c, + C: Fn(&str, &str) -> Ordering + Send + UnwindSafe + 'static, { unsafe extern "C" fn call_boxed_closure( arg1: *mut c_void, diff --git a/src/functions.rs b/src/functions.rs index f5e051d..39973d3 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -380,15 +380,15 @@ impl Connection { /// /// Will return Err if the function could not be attached to the connection. #[inline] - pub fn create_scalar_function<'c, F, T>( - &'c self, + pub fn create_scalar_function( + &self, fn_name: &str, n_arg: c_int, flags: FunctionFlags, x_func: F, ) -> Result<()> where - F: FnMut(&Context<'_>) -> Result + Send + UnwindSafe + 'c, + F: FnMut(&Context<'_>) -> Result + Send + UnwindSafe + 'static, T: ToSql, { self.db @@ -462,15 +462,15 @@ impl Connection { } impl InnerConnection { - fn create_scalar_function<'c, F, T>( - &'c mut self, + fn create_scalar_function( + &mut self, fn_name: &str, n_arg: c_int, flags: FunctionFlags, x_func: F, ) -> Result<()> where - F: FnMut(&Context<'_>) -> Result + Send + UnwindSafe + 'c, + F: FnMut(&Context<'_>) -> Result + Send + UnwindSafe + 'static, T: ToSql, { unsafe extern "C" fn call_boxed_closure( diff --git a/src/hooks.rs b/src/hooks.rs index 1c9dbdf..9684008 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -345,9 +345,9 @@ impl Connection { /// /// The callback returns `true` to rollback. #[inline] - pub fn commit_hook<'c, F>(&'c self, hook: Option) + pub fn commit_hook(&self, hook: Option) where - F: FnMut() -> bool + Send + 'c, + F: FnMut() -> bool + Send + 'static, { self.db.borrow_mut().commit_hook(hook); } @@ -357,9 +357,9 @@ impl Connection { /// /// The callback returns `true` to rollback. #[inline] - pub fn rollback_hook<'c, F>(&'c self, hook: Option) + pub fn rollback_hook(&self, hook: Option) where - F: FnMut() + Send + 'c, + F: FnMut() + Send + 'static, { self.db.borrow_mut().rollback_hook(hook); } @@ -375,9 +375,9 @@ impl Connection { /// - the name of the table that is updated, /// - the ROWID of the row that is updated. #[inline] - pub fn update_hook<'c, F>(&'c self, hook: Option) + pub fn update_hook(&self, hook: Option) where - F: FnMut(Action, &str, &str, i64) + Send + 'c, + F: FnMut(Action, &str, &str, i64) + Send + 'static, { self.db.borrow_mut().update_hook(hook); } @@ -418,9 +418,9 @@ impl InnerConnection { self.authorizer(None::) -> Authorization>); } - fn commit_hook<'c, F>(&'c mut self, hook: Option) + fn commit_hook(&mut self, hook: Option) where - F: FnMut() -> bool + Send + 'c, + F: FnMut() -> bool + Send + 'static, { unsafe extern "C" fn call_boxed_closure(p_arg: *mut c_void) -> c_int where @@ -467,9 +467,9 @@ impl InnerConnection { self.free_commit_hook = free_commit_hook; } - fn rollback_hook<'c, F>(&'c mut self, hook: Option) + fn rollback_hook(&mut self, hook: Option) where - F: FnMut() + Send + 'c, + F: FnMut() + Send + 'static, { unsafe extern "C" fn call_boxed_closure(p_arg: *mut c_void) where @@ -508,9 +508,9 @@ impl InnerConnection { self.free_rollback_hook = free_rollback_hook; } - fn update_hook<'c, F>(&'c mut self, hook: Option) + fn update_hook(&mut self, hook: Option) where - F: FnMut(Action, &str, &str, i64) + Send + 'c, + F: FnMut(Action, &str, &str, i64) + Send + 'static, { unsafe extern "C" fn call_boxed_closure( p_arg: *mut c_void, @@ -698,13 +698,13 @@ mod test { fn test_commit_hook() -> Result<()> { let db = Connection::open_in_memory()?; - let mut called = false; + static CALLED: AtomicBool = AtomicBool::new(false); db.commit_hook(Some(|| { - called = true; + CALLED.store(true, Ordering::Relaxed); false })); db.execute_batch("BEGIN; CREATE TABLE foo (t TEXT); COMMIT;")?; - assert!(called); + assert!(CALLED.load(Ordering::Relaxed)); Ok(()) } @@ -726,12 +726,12 @@ mod test { fn test_rollback_hook() -> Result<()> { let db = Connection::open_in_memory()?; - let mut called = false; + static CALLED: AtomicBool = AtomicBool::new(false); db.rollback_hook(Some(|| { - called = true; + CALLED.store(true, Ordering::Relaxed); })); db.execute_batch("BEGIN; CREATE TABLE foo (t TEXT); ROLLBACK;")?; - assert!(called); + assert!(CALLED.load(Ordering::Relaxed)); Ok(()) } @@ -739,17 +739,17 @@ mod test { fn test_update_hook() -> Result<()> { let db = Connection::open_in_memory()?; - let mut called = false; + static CALLED: AtomicBool = AtomicBool::new(false); db.update_hook(Some(|action, db: &str, tbl: &str, row_id| { assert_eq!(Action::SQLITE_INSERT, action); assert_eq!("main", db); assert_eq!("foo", tbl); assert_eq!(1, row_id); - called = true; + CALLED.store(true, Ordering::Relaxed); })); db.execute_batch("CREATE TABLE foo (t TEXT)")?; db.execute_batch("INSERT INTO foo VALUES ('lisa')")?; - assert!(called); + assert!(CALLED.load(Ordering::Relaxed)); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 0f5601b..531b37f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -159,9 +159,11 @@ pub const NO_PARAMS: &[&dyn ToSql] = &[]; /// } /// /// fn add_person(conn: &Connection, person: &Person) -> Result<()> { -/// conn.execute("INSERT INTO person (name, age_in_years, data) +/// conn.execute( +/// "INSERT INTO person (name, age_in_years, data) /// VALUES (?1, ?2, ?3)", -/// params![person.name, person.age_in_years, person.data])?; +/// params![person.name, person.age_in_years, person.data], +/// )?; /// Ok(()) /// } /// ``` @@ -193,11 +195,11 @@ macro_rules! params { /// conn.execute( /// "INSERT INTO person (name, age_in_years, data) /// VALUES (:name, :age, :data)", -/// named_params!{ +/// named_params! { /// ":name": person.name, /// ":age": person.age_in_years, /// ":data": person.data, -/// } +/// }, /// )?; /// Ok(()) /// } @@ -462,10 +464,11 @@ impl Connection { /// ```rust,no_run /// # use rusqlite::{Connection, Result}; /// fn create_tables(conn: &Connection) -> Result<()> { - /// conn.execute_batch("BEGIN; - /// CREATE TABLE foo(x INTEGER); - /// CREATE TABLE bar(y TEXT); - /// COMMIT;", + /// conn.execute_batch( + /// "BEGIN; + /// CREATE TABLE foo(x INTEGER); + /// CREATE TABLE bar(y TEXT); + /// COMMIT;", /// ) /// } /// ``` @@ -515,7 +518,10 @@ impl Connection { /// ```rust,no_run /// # use rusqlite::{params, Connection}; /// fn update_rows(conn: &Connection) { - /// match conn.execute("UPDATE foo SET bar = 'baz' WHERE qux = ?1 AND quux = ?2", params![1i32, 1.5f64]) { + /// match conn.execute( + /// "UPDATE foo SET bar = 'baz' WHERE qux = ?1 AND quux = ?2", + /// params![1i32, 1.5f64], + /// ) { /// Ok(updated) => println!("{} rows were updated", updated), /// Err(err) => println!("update failed: {}", err), /// } diff --git a/src/params.rs b/src/params.rs index b817ced..ddbe8a8 100644 --- a/src/params.rs +++ b/src/params.rs @@ -116,7 +116,7 @@ use sealed::Sealed; /// fn insert(conn: &Connection) -> Result<()> { /// let mut stmt = conn.prepare("INSERT INTO test (key, value) VALUES (:key, :value)")?; /// // Using `rusqlite::params!`: -/// stmt.execute(named_params!{ ":key": "one", ":val": 2 })?; +/// stmt.execute(named_params! { ":key": "one", ":val": 2 })?; /// // Alternatively: /// stmt.execute(&[(":key", "three"), (":val", "four")])?; /// // Or: @@ -251,7 +251,7 @@ impl_for_array_ref!( /// ## Basic usage /// /// ```rust,no_run -/// use rusqlite::{Connection, Result, params_from_iter}; +/// use rusqlite::{params_from_iter, Connection, Result}; /// use std::collections::BTreeSet; /// /// fn query(conn: &Connection, ids: &BTreeSet) -> Result<()> { diff --git a/src/statement.rs b/src/statement.rs index fd6df71..04c71ef 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -55,7 +55,7 @@ impl Statement<'_> { /// // The `rusqlite::named_params!` macro (like `params!`) is useful for heterogeneous /// // sets of parameters (where all parameters are not the same type), or for queries /// // with many (more than 32) statically known parameters. - /// stmt.execute(named_params!{ ":key": "one", ":val": 2 })?; + /// stmt.execute(named_params! { ":key": "one", ":val": 2 })?; /// // However, named parameters can also be passed like: /// stmt.execute(&[(":key", "three"), (":val", "four")])?; /// // Or even: (note that a &T is required for the value type, currently) @@ -208,7 +208,7 @@ impl Statement<'_> { /// # use rusqlite::{Connection, Result, named_params}; /// fn query(conn: &Connection) -> Result<()> { /// let mut stmt = conn.prepare("SELECT * FROM test where name = :name")?; - /// let mut rows = stmt.query(named_params!{ ":name": "one" })?; + /// let mut rows = stmt.query(named_params! { ":name": "one" })?; /// while let Some(row) = rows.next()? { /// // ... /// } @@ -346,13 +346,12 @@ impl Statement<'_> { /// /// fn name_to_person(name: String) -> Result { /// // ... check for valid name - /// Ok(Person { name: name }) + /// Ok(Person { name }) /// } /// /// fn get_names(conn: &Connection) -> Result> { /// let mut stmt = conn.prepare("SELECT name FROM people WHERE id = :id")?; - /// let rows = - /// stmt.query_and_then(&[(":id", "one")], |row| name_to_person(row.get(0)?))?; + /// let rows = stmt.query_and_then(&[(":id", "one")], |row| name_to_person(row.get(0)?))?; /// /// let mut persons = Vec::new(); /// for person_result in rows {