diff --git a/README.md b/README.md index 7629fe7..9bdfa39 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,6 @@ Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expo an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgres). ```rust -extern crate rusqlite; -extern crate time; - use rusqlite::types::ToSql; use rusqlite::{Connection, NO_PARAMS}; use time::Timespec; diff --git a/benches/lib.rs b/benches/lib.rs index 421e0ec..d1b6d79 100644 --- a/benches/lib.rs +++ b/benches/lib.rs @@ -1,9 +1,6 @@ -#![feature(extern_crate_item_prelude)] #![feature(test)] extern crate test; -extern crate rusqlite; - use rusqlite::Connection; use test::Bencher; diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index a98662c..9da7810 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -9,7 +9,7 @@ fn main() { #[cfg(feature = "bundled")] mod build { - extern crate cc; + use cc; use std::path::Path; pub fn main(out_dir: &str, out_path: &Path) { @@ -94,7 +94,7 @@ impl From for String { #[cfg(not(feature = "bundled"))] mod build { - extern crate pkg_config; + use pkg_config; #[cfg(all(feature = "vcpkg", target_env = "msvc"))] extern crate vcpkg; @@ -201,7 +201,7 @@ mod bindings { #[cfg(feature = "buildtime_bindgen")] mod bindings { - extern crate bindgen; + use bindgen; use self::bindgen::callbacks::{IntKind, ParseCallbacks}; use super::HeaderLocation; diff --git a/libsqlite3-sys/src/error.rs b/libsqlite3-sys/src/error.rs index 0be28ed..bf1367f 100644 --- a/libsqlite3-sys/src/error.rs +++ b/libsqlite3-sys/src/error.rs @@ -98,7 +98,7 @@ impl Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Error code {}: {}", diff --git a/src/backup.rs b/src/backup.rs index 250e0c8..0253ecb 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -57,7 +57,7 @@ impl Connection { /// or if the backup fails. pub fn backup>( &self, - name: DatabaseName, + name: DatabaseName<'_>, dst_path: P, progress: Option, ) -> Result<()> { @@ -95,7 +95,7 @@ impl Connection { /// or if the restore fails. pub fn restore, F: Fn(Progress)>( &mut self, - name: DatabaseName, + name: DatabaseName<'_>, src_path: P, progress: Option, ) -> Result<()> { @@ -192,9 +192,9 @@ impl<'a, 'b> Backup<'a, 'b> { /// `NULL`. pub fn new_with_names( from: &'a Connection, - from_name: DatabaseName, + from_name: DatabaseName<'_>, to: &'b mut Connection, - to_name: DatabaseName, + to_name: DatabaseName<'_>, ) -> Result> { let to_name = to_name.to_cstring()?; let from_name = from_name.to_cstring()?; diff --git a/src/blob.rs b/src/blob.rs index 0b41a5f..050d84d 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -84,7 +84,7 @@ impl Connection { /// fails. pub fn blob_open<'a>( &'a self, - db: DatabaseName, + db: DatabaseName<'_>, table: &str, column: &str, row_id: i64, @@ -254,7 +254,7 @@ impl<'conn> Drop for Blob<'conn> { pub struct ZeroBlob(pub i32); impl ToSql for ZeroBlob { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { let ZeroBlob(length) = *self; Ok(ToSqlOutput::ZeroBlob(length)) } diff --git a/src/busy.rs b/src/busy.rs index dc7a889..2dca96d 100644 --- a/src/busy.rs +++ b/src/busy.rs @@ -74,12 +74,12 @@ impl InnerConnection { #[cfg(test)] mod test { - extern crate tempdir; use self::tempdir::TempDir; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::sync_channel; use std::thread; use std::time::Duration; + use tempdir; use crate::{Connection, Error, ErrorCode, TransactionBehavior, NO_PARAMS}; diff --git a/src/error.rs b/src/error.rs index 8f324dd..f451b4e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -19,7 +19,7 @@ pub enum Error { /// Error when the value of a particular column is requested, but it cannot /// be converted to the requested Rust type. - FromSqlConversionFailure(usize, Type, Box), + FromSqlConversionFailure(usize, Type, Box), /// Error when SQLite gives us an integral value outside the range of the /// requested type (e.g., trying to get the value 1000 into a `u8`). @@ -78,10 +78,10 @@ pub enum Error { /// `create_scalar_function`). #[cfg(feature = "functions")] #[allow(dead_code)] - UserFunctionError(Box), + UserFunctionError(Box), /// Error available for the implementors of the `ToSql` trait. - ToSqlConversionFailure(Box), + ToSqlConversionFailure(Box), /// Error when the SQL is not a `SELECT`, is not read-only. InvalidQuery, @@ -106,7 +106,7 @@ impl From<::std::ffi::NulError> for Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Error::SqliteFailure(ref err, None) => err.fmt(f), Error::SqliteFailure(_, Some(ref s)) => write!(f, "{}", s), @@ -191,7 +191,7 @@ impl error::Error for Error { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { Error::SqliteFailure(ref err, _) => Some(err), Error::Utf8Error(ref err) => Some(err), diff --git a/src/functions.rs b/src/functions.rs index 5e141a4..c265eeb 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -198,7 +198,7 @@ where /// "step" function called once for each row in an aggregate group. May be /// called 0 times if there are no rows. - fn step(&self, _: &mut Context, _: &mut A) -> Result<()>; + fn step(&self, _: &mut Context<'_>, _: &mut A) -> Result<()>; /// Computes and returns the final result. Will be called exactly once for /// each invocation of the function. If `step()` was called at least @@ -246,7 +246,7 @@ impl Connection { x_func: F, ) -> Result<()> where - F: FnMut(&Context) -> Result + Send + 'static, + F: FnMut(&Context<'_>) -> Result + Send + 'static, T: ToSql, { self.db @@ -297,7 +297,7 @@ impl InnerConnection { x_func: F, ) -> Result<()> where - F: FnMut(&Context) -> Result + Send + 'static, + F: FnMut(&Context<'_>) -> Result + Send + 'static, T: ToSql, { unsafe extern "C" fn call_boxed_closure( @@ -305,7 +305,7 @@ impl InnerConnection { argc: c_int, argv: *mut *mut sqlite3_value, ) where - F: FnMut(&Context) -> Result, + F: FnMut(&Context<'_>) -> Result, T: ToSql, { let ctx = Context { @@ -483,7 +483,7 @@ impl InnerConnection { #[cfg(test)] mod test { - extern crate regex; + use regex; use self::regex::Regex; use std::collections::HashMap; @@ -493,7 +493,7 @@ mod test { use crate::functions::{Aggregate, Context}; use crate::{Connection, Error, Result, NO_PARAMS}; - fn half(ctx: &Context) -> Result { + fn half(ctx: &Context<'_>) -> Result { assert!(ctx.len() == 1, "called with unexpected number of arguments"); let value = ctx.get::(0)?; Ok(value / 2f64) @@ -523,7 +523,7 @@ mod test { // This implementation of a regexp scalar function uses SQLite's auxilliary data // (https://www.sqlite.org/c3ref/get_auxdata.html) to avoid recompiling the regular // expression multiple times within one query. - fn regexp_with_auxilliary(ctx: &Context) -> Result { + fn regexp_with_auxilliary(ctx: &Context<'_>) -> Result { assert!(ctx.len() == 2, "called with unexpected number of arguments"); let saved_re: Option<&Regex> = unsafe { ctx.get_aux(0) }; @@ -674,7 +674,7 @@ mod test { 0 } - fn step(&self, ctx: &mut Context, sum: &mut i64) -> Result<()> { + fn step(&self, ctx: &mut Context<'_>, sum: &mut i64) -> Result<()> { *sum += ctx.get::(0)?; Ok(()) } @@ -689,7 +689,7 @@ mod test { 0 } - fn step(&self, _ctx: &mut Context, sum: &mut i64) -> Result<()> { + fn step(&self, _ctx: &mut Context<'_>, sum: &mut i64) -> Result<()> { *sum += 1; Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index e5165e8..3ef9d8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,17 +62,14 @@ //! ``` #![allow(unknown_lints)] -extern crate libsqlite3_sys as ffi; -extern crate lru_cache; +use libsqlite3_sys as ffi; + #[macro_use] extern crate bitflags; #[cfg(any(test, feature = "vtab"))] #[macro_use] extern crate lazy_static; -#[cfg(feature = "i128_blob")] -extern crate byteorder; - use std::cell::RefCell; use std::convert; use std::default::Default; @@ -142,7 +139,7 @@ pub mod vtab; // Number of cached prepared statements we'll hold on to. const STATEMENT_CACHE_DEFAULT_CAPACITY: usize = 16; /// To be used when your statement has no [parameter](https://sqlite.org/lang_expr.html#varparam). -pub const NO_PARAMS: &[&ToSql] = &[]; +pub const NO_PARAMS: &[&dyn ToSql] = &[]; /// A typedef of the result returned by many methods. pub type Result = result::Result; @@ -343,7 +340,7 @@ impl Connection { /// /// Will return `Err` if `sql` cannot be converted to a C-compatible string /// or if the underlying SQLite call fails. - pub fn execute_named(&self, sql: &str, params: &[(&str, &ToSql)]) -> Result { + pub fn execute_named(&self, sql: &str, params: &[(&str, &dyn ToSql)]) -> Result { self.prepare(sql) .and_then(|mut stmt| stmt.execute_named(params)) } @@ -383,7 +380,7 @@ impl Connection { where P: IntoIterator, P::Item: ToSql, - F: FnOnce(&Row) -> T, + F: FnOnce(&Row<'_, '_>) -> T, { let mut stmt = self.prepare(sql)?; stmt.query_row(params, f) @@ -399,9 +396,9 @@ impl Connection { /// /// Will return `Err` if `sql` cannot be converted to a C-compatible string /// or if the underlying SQLite call fails. - pub fn query_row_named(&self, sql: &str, params: &[(&str, &ToSql)], f: F) -> Result + pub fn query_row_named(&self, sql: &str, params: &[(&str, &dyn ToSql)], f: F) -> Result where - F: FnOnce(&Row) -> T, + F: FnOnce(&Row<'_, '_>) -> T, { let mut stmt = self.prepare(sql)?; let mut rows = stmt.query_named(params)?; @@ -438,7 +435,7 @@ impl Connection { where P: IntoIterator, P::Item: ToSql, - F: FnOnce(&Row) -> result::Result, + F: FnOnce(&Row<'_, '_>) -> result::Result, E: convert::From, { let mut stmt = self.prepare(sql)?; @@ -594,7 +591,7 @@ impl Connection { } impl fmt::Debug for Connection { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Connection") .field("path", &self.path) .finish() @@ -1055,12 +1052,12 @@ impl Drop for InnerConnection { #[cfg(test)] mod test { - extern crate tempdir; use self::tempdir::TempDir; pub use super::*; use crate::ffi; pub use std::error::Error as StdError; pub use std::fmt; + use tempdir; // this function is never called, but is still type checked; in // particular, calls with specific instantiations will require @@ -1548,7 +1545,9 @@ mod test { for (i, v) in vals.iter().enumerate() { let i_to_insert = i as i64; assert_eq!( - insert_stmt.execute(&[&i_to_insert as &ToSql, &v]).unwrap(), + insert_stmt + .execute(&[&i_to_insert as &dyn ToSql, &v]) + .unwrap(), 1 ); } @@ -1566,7 +1565,7 @@ mod test { } mod query_and_then_tests { - extern crate libsqlite3_sys as ffi; + use super::*; #[derive(Debug)] @@ -1576,7 +1575,7 @@ mod test { } impl fmt::Display for CustomError { - fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { match *self { CustomError::SomeError => write!(f, "{}", self.description()), CustomError::Sqlite(ref se) => write!(f, "{}: {}", self.description(), se), @@ -1589,7 +1588,7 @@ mod test { "my custom error" } - fn cause(&self) -> Option<&StdError> { + fn cause(&self) -> Option<&dyn StdError> { match *self { CustomError::SomeError => None, CustomError::Sqlite(ref se) => Some(se), diff --git a/src/load_extension_guard.rs b/src/load_extension_guard.rs index 49fafff..096e6ac 100644 --- a/src/load_extension_guard.rs +++ b/src/load_extension_guard.rs @@ -21,7 +21,7 @@ impl<'conn> LoadExtensionGuard<'conn> { /// Attempt to enable loading extensions. Loading extensions will be /// disabled when this guard goes out of scope. Cannot be meaningfully /// nested. - pub fn new(conn: &Connection) -> Result { + pub fn new(conn: &Connection) -> Result> { conn.load_extension_enable() .map(|_| LoadExtensionGuard { conn }) } diff --git a/src/row.rs b/src/row.rs index 545e190..fca2509 100644 --- a/src/row.rs +++ b/src/row.rs @@ -73,7 +73,7 @@ pub struct MappedRows<'stmt, F> { impl<'stmt, T, F> MappedRows<'stmt, F> where - F: FnMut(&Row) -> T, + F: FnMut(&Row<'_, '_>) -> T, { pub(crate) fn new(rows: Rows<'stmt>, f: F) -> MappedRows<'stmt, F> { MappedRows { rows, map: f } @@ -82,7 +82,7 @@ where impl<'conn, T, F> Iterator for MappedRows<'conn, F> where - F: FnMut(&Row) -> T, + F: FnMut(&Row<'_, '_>) -> T, { type Item = Result; @@ -103,7 +103,7 @@ pub struct AndThenRows<'stmt, F> { impl<'stmt, T, E, F> AndThenRows<'stmt, F> where - F: FnMut(&Row) -> result::Result, + F: FnMut(&Row<'_, '_>) -> result::Result, { pub(crate) fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F> { AndThenRows { rows, map: f } @@ -113,7 +113,7 @@ where impl<'stmt, T, E, F> Iterator for AndThenRows<'stmt, F> where E: convert::From, - F: FnMut(&Row) -> result::Result, + F: FnMut(&Row<'_, '_>) -> result::Result, { type Item = result::Result; @@ -231,12 +231,12 @@ impl<'a, 'stmt> Row<'a, 'stmt> { pub trait RowIndex { /// Returns the index of the appropriate column, or `None` if no such /// column exists. - fn idx(&self, stmt: &Statement) -> Result; + fn idx(&self, stmt: &Statement<'_>) -> Result; } impl RowIndex for usize { #[inline] - fn idx(&self, stmt: &Statement) -> Result { + fn idx(&self, stmt: &Statement<'_>) -> Result { if *self >= stmt.column_count() { Err(Error::InvalidColumnIndex(*self)) } else { @@ -247,7 +247,7 @@ impl RowIndex for usize { impl<'a> RowIndex for &'a str { #[inline] - fn idx(&self, stmt: &Statement) -> Result { + fn idx(&self, stmt: &Statement<'_>) -> Result { stmt.column_index(*self) } } diff --git a/src/statement.rs b/src/statement.rs index ce49943..1bcf4ed 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -117,7 +117,7 @@ impl<'conn> Statement<'conn> { /// Will return `Err` if binding parameters fails, the executed statement /// returns rows (in which case `query` should be used instead), or the /// underling SQLite call fails. - pub fn execute_named(&mut self, params: &[(&str, &ToSql)]) -> Result { + pub fn execute_named(&mut self, params: &[(&str, &dyn ToSql)]) -> Result { self.bind_parameters_named(params)?; self.execute_with_bound_parameters() } @@ -208,7 +208,7 @@ impl<'conn> Statement<'conn> { /// # Failure /// /// Will return `Err` if binding parameters fails. - pub fn query_named<'a>(&'a mut self, params: &[(&str, &ToSql)]) -> Result> { + pub fn query_named<'a>(&'a mut self, params: &[(&str, &dyn ToSql)]) -> Result> { self.check_readonly()?; self.bind_parameters_named(params)?; Ok(Rows::new(self)) @@ -241,7 +241,7 @@ impl<'conn> Statement<'conn> { where P: IntoIterator, P::Item: ToSql, - F: FnMut(&Row) -> T, + F: FnMut(&Row<'_, '_>) -> T, { let rows = self.query(params)?; Ok(MappedRows::new(rows, f)) @@ -276,11 +276,11 @@ impl<'conn> Statement<'conn> { /// Will return `Err` if binding parameters fails. pub fn query_map_named<'a, T, F>( &'a mut self, - params: &[(&str, &ToSql)], + params: &[(&str, &dyn ToSql)], f: F, ) -> Result> where - F: FnMut(&Row) -> T, + F: FnMut(&Row<'_, '_>) -> T, { let rows = self.query_named(params)?; Ok(MappedRows::new(rows, f)) @@ -302,7 +302,7 @@ impl<'conn> Statement<'conn> { P: IntoIterator, P::Item: ToSql, E: convert::From, - F: FnMut(&Row) -> result::Result, + F: FnMut(&Row<'_, '_>) -> result::Result, { let rows = self.query(params)?; Ok(AndThenRows::new(rows, f)) @@ -348,12 +348,12 @@ impl<'conn> Statement<'conn> { /// Will return `Err` if binding parameters fails. pub fn query_and_then_named<'a, T, E, F>( &'a mut self, - params: &[(&str, &ToSql)], + params: &[(&str, &dyn ToSql)], f: F, ) -> Result> where E: convert::From, - F: FnMut(&Row) -> result::Result, + F: FnMut(&Row<'_, '_>) -> result::Result, { let rows = self.query_named(params)?; Ok(AndThenRows::new(rows, f)) @@ -384,7 +384,7 @@ impl<'conn> Statement<'conn> { where P: IntoIterator, P::Item: ToSql, - F: FnOnce(&Row) -> T, + F: FnOnce(&Row<'_, '_>) -> T, { let mut rows = self.query(params)?; @@ -437,7 +437,7 @@ impl<'conn> Statement<'conn> { Ok(()) } - fn bind_parameters_named(&mut self, params: &[(&str, &ToSql)]) -> Result<()> { + fn bind_parameters_named(&mut self, params: &[(&str, &dyn ToSql)]) -> Result<()> { for &(name, value) in params { if let Some(i) = self.parameter_index(name)? { self.bind_parameter(value, i)?; @@ -448,7 +448,7 @@ impl<'conn> Statement<'conn> { Ok(()) } - fn bind_parameter(&self, param: &ToSql, col: usize) -> Result<()> { + fn bind_parameter(&self, param: &dyn ToSql, col: usize) -> Result<()> { let value = param.to_sql()?; let ptr = unsafe { self.stmt.ptr() }; @@ -576,7 +576,7 @@ impl<'conn> Into for Statement<'conn> { } impl<'conn> fmt::Debug for Statement<'conn> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let sql = str::from_utf8(self.stmt.sql().to_bytes()); f.debug_struct("Statement") .field("conn", self.conn) @@ -594,11 +594,11 @@ impl<'conn> Drop for Statement<'conn> { } impl<'conn> Statement<'conn> { - pub(crate) fn new(conn: &Connection, stmt: RawStatement) -> Statement { + pub(crate) fn new(conn: &Connection, stmt: RawStatement) -> Statement<'_> { Statement { conn, stmt } } - pub(crate) fn value_ref(&self, col: usize) -> ValueRef { + pub(crate) fn value_ref(&self, col: usize) -> ValueRef<'_> { let raw = unsafe { self.stmt.ptr() }; match self.stmt.column_type(col) { diff --git a/src/transaction.rs b/src/transaction.rs index 4907aaf..b717cd7 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -92,7 +92,7 @@ impl<'conn> Transaction<'conn> { /// Even though we don't mutate the connection, we take a `&mut Connection` /// so as to prevent nested or concurrent transactions on the same /// connection. - pub fn new(conn: &mut Connection, behavior: TransactionBehavior) -> Result { + pub fn new(conn: &mut Connection, behavior: TransactionBehavior) -> Result> { let query = match behavior { TransactionBehavior::Deferred => "BEGIN DEFERRED", TransactionBehavior::Immediate => "BEGIN IMMEDIATE", @@ -131,12 +131,12 @@ impl<'conn> Transaction<'conn> { /// tx.commit() /// } /// ``` - pub fn savepoint(&mut self) -> Result { + pub fn savepoint(&mut self) -> Result> { Savepoint::with_depth(self.conn, 1) } /// Create a new savepoint with a custom savepoint name. See `savepoint()`. - pub fn savepoint_with_name>(&mut self, name: T) -> Result { + pub fn savepoint_with_name>(&mut self, name: T) -> Result> { Savepoint::with_depth_and_name(self.conn, 1, name) } @@ -214,7 +214,7 @@ impl<'conn> Savepoint<'conn> { conn: &Connection, depth: u32, name: T, - ) -> Result { + ) -> Result> { let name = name.into(); conn.execute_batch(&format!("SAVEPOINT {}", name)) .map(|_| Savepoint { @@ -226,28 +226,28 @@ impl<'conn> Savepoint<'conn> { }) } - fn with_depth(conn: &Connection, depth: u32) -> Result { + fn with_depth(conn: &Connection, depth: u32) -> Result> { let name = format!("_rusqlite_sp_{}", depth); Savepoint::with_depth_and_name(conn, depth, name) } /// Begin a new savepoint. Can be nested. - pub fn new(conn: &mut Connection) -> Result { + pub fn new(conn: &mut Connection) -> Result> { Savepoint::with_depth(conn, 0) } /// Begin a new savepoint with a user-provided savepoint name. - pub fn with_name>(conn: &mut Connection, name: T) -> Result { + pub fn with_name>(conn: &mut Connection, name: T) -> Result> { Savepoint::with_depth_and_name(conn, 0, name) } /// Begin a nested savepoint. - pub fn savepoint(&mut self) -> Result { + pub fn savepoint(&mut self) -> Result> { Savepoint::with_depth(self.conn, self.depth + 1) } /// Begin a nested savepoint with a user-provided savepoint name. - pub fn savepoint_with_name>(&mut self, name: T) -> Result { + pub fn savepoint_with_name>(&mut self, name: T) -> Result> { Savepoint::with_depth_and_name(self.conn, self.depth + 1, name) } @@ -348,7 +348,7 @@ impl Connection { /// # Failure /// /// Will return `Err` if the underlying SQLite call fails. - pub fn transaction(&mut self) -> Result { + pub fn transaction(&mut self) -> Result> { Transaction::new(self, TransactionBehavior::Deferred) } @@ -362,7 +362,7 @@ impl Connection { pub fn transaction_with_behavior( &mut self, behavior: TransactionBehavior, - ) -> Result { + ) -> Result> { Transaction::new(self, behavior) } @@ -391,7 +391,7 @@ impl Connection { /// # Failure /// /// Will return `Err` if the underlying SQLite call fails. - pub fn savepoint(&mut self) -> Result { + pub fn savepoint(&mut self) -> Result> { Savepoint::new(self) } @@ -402,7 +402,7 @@ impl Connection { /// # Failure /// /// Will return `Err` if the underlying SQLite call fails. - pub fn savepoint_with_name>(&mut self, name: T) -> Result { + pub fn savepoint_with_name>(&mut self, name: T) -> Result> { Savepoint::with_name(self, name) } } diff --git a/src/types/chrono.rs b/src/types/chrono.rs index 776a55c..4f73146 100644 --- a/src/types/chrono.rs +++ b/src/types/chrono.rs @@ -1,5 +1,5 @@ //! Convert most of the [Time Strings](http://sqlite.org/lang_datefunc.html) to chrono types. -extern crate chrono; +use chrono; use std::borrow::Cow; @@ -10,7 +10,7 @@ use crate::Result; /// ISO 8601 calendar date without timezone => "YYYY-MM-DD" impl ToSql for NaiveDate { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { let date_str = self.format("%Y-%m-%d").to_string(); Ok(ToSqlOutput::from(date_str)) } @@ -18,7 +18,7 @@ impl ToSql for NaiveDate { /// "YYYY-MM-DD" => ISO 8601 calendar date without timezone. impl FromSql for NaiveDate { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { value .as_str() .and_then(|s| match NaiveDate::parse_from_str(s, "%Y-%m-%d") { @@ -30,7 +30,7 @@ impl FromSql for NaiveDate { /// ISO 8601 time without timezone => "HH:MM:SS.SSS" impl ToSql for NaiveTime { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { let date_str = self.format("%H:%M:%S%.f").to_string(); Ok(ToSqlOutput::from(date_str)) } @@ -38,7 +38,7 @@ impl ToSql for NaiveTime { /// "HH:MM"/"HH:MM:SS"/"HH:MM:SS.SSS" => ISO 8601 time without timezone. impl FromSql for NaiveTime { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { value.as_str().and_then(|s| { let fmt = match s.len() { 5 => "%H:%M", @@ -56,7 +56,7 @@ impl FromSql for NaiveTime { /// ISO 8601 combined date and time without timezone => /// "YYYY-MM-DD HH:MM:SS.SSS" impl ToSql for NaiveDateTime { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { let date_str = self.format("%Y-%m-%dT%H:%M:%S%.f").to_string(); Ok(ToSqlOutput::from(date_str)) } @@ -66,7 +66,7 @@ impl ToSql for NaiveDateTime { /// and time without timezone. ("YYYY-MM-DDTHH:MM:SS"/"YYYY-MM-DDTHH:MM:SS.SSS" /// also supported) impl FromSql for NaiveDateTime { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { value.as_str().and_then(|s| { let fmt = if s.len() >= 11 && s.as_bytes()[10] == b'T' { "%Y-%m-%dT%H:%M:%S%.f" @@ -85,14 +85,14 @@ impl FromSql for NaiveDateTime { /// Date and time with time zone => UTC RFC3339 timestamp /// ("YYYY-MM-DDTHH:MM:SS.SSS+00:00"). impl ToSql for DateTime { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(self.with_timezone(&Utc).to_rfc3339())) } } /// RFC3339 ("YYYY-MM-DDTHH:MM:SS.SSS[+-]HH:MM") into `DateTime`. impl FromSql for DateTime { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { { // Try to parse value as rfc3339 first. let s = value.as_str()?; @@ -121,7 +121,7 @@ impl FromSql for DateTime { /// RFC3339 ("YYYY-MM-DDTHH:MM:SS.SSS[+-]HH:MM") into `DateTime`. impl FromSql for DateTime { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { let utc_dt = DateTime::::column_result(value)?; Ok(utc_dt.with_timezone(&Local)) } diff --git a/src/types/from_sql.rs b/src/types/from_sql.rs index 4feefdf..b36e079 100644 --- a/src/types/from_sql.rs +++ b/src/types/from_sql.rs @@ -19,11 +19,11 @@ pub enum FromSqlError { InvalidI128Size(usize), /// An error case available for implementors of the `FromSql` trait. - Other(Box), + Other(Box), } impl fmt::Display for FromSqlError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { FromSqlError::InvalidType => write!(f, "Invalid type"), FromSqlError::OutOfRange(i) => write!(f, "Value {} out of range", i), @@ -48,7 +48,7 @@ impl Error for FromSqlError { } #[allow(clippy::match_same_arms)] - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match *self { FromSqlError::Other(ref err) => err.cause(), FromSqlError::InvalidType | FromSqlError::OutOfRange(_) => None, @@ -73,11 +73,11 @@ pub type FromSqlResult = Result; /// fetching values as i64 and then doing the interpretation themselves or by /// defining a newtype and implementing `FromSql`/`ToSql` for it. pub trait FromSql: Sized { - fn column_result(value: ValueRef) -> FromSqlResult; + fn column_result(value: ValueRef<'_>) -> FromSqlResult; } impl FromSql for isize { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { i64::column_result(value).and_then(|i| { if i < isize::min_value() as i64 || i > isize::max_value() as i64 { Err(FromSqlError::OutOfRange(i)) @@ -91,7 +91,7 @@ impl FromSql for isize { macro_rules! from_sql_integral( ($t:ident) => ( impl FromSql for $t { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { i64::column_result(value).and_then(|i| { if i < i64::from($t::min_value()) || i > i64::from($t::max_value()) { Err(FromSqlError::OutOfRange(i)) @@ -112,13 +112,13 @@ from_sql_integral!(u16); from_sql_integral!(u32); impl FromSql for i64 { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { value.as_i64() } } impl FromSql for f64 { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { match value { ValueRef::Integer(i) => Ok(i as f64), ValueRef::Real(f) => Ok(f), @@ -128,7 +128,7 @@ impl FromSql for f64 { } impl FromSql for bool { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { i64::column_result(value).map(|i| match i { 0 => false, _ => true, @@ -137,20 +137,20 @@ impl FromSql for bool { } impl FromSql for String { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { value.as_str().map(|s| s.to_string()) } } impl FromSql for Vec { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { value.as_blob().map(|b| b.to_vec()) } } #[cfg(feature = "i128_blob")] impl FromSql for i128 { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { use byteorder::{BigEndian, ByteOrder}; value.as_blob().and_then(|bytes| { @@ -164,7 +164,7 @@ impl FromSql for i128 { } impl FromSql for Option { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { match value { ValueRef::Null => Ok(None), _ => FromSql::column_result(value).map(Some), @@ -173,7 +173,7 @@ impl FromSql for Option { } impl FromSql for Value { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { Ok(value.into()) } } diff --git a/src/types/mod.rs b/src/types/mod.rs index 0d19dc1..6f5d78d 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -98,7 +98,7 @@ pub enum Type { } impl fmt::Display for Type { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Type::Null => write!(f, "Null"), Type::Integer => write!(f, "Integer"), @@ -111,7 +111,7 @@ impl fmt::Display for Type { #[cfg(test)] mod test { - extern crate time; + use time; use super::Value; use crate::{Connection, Error, NO_PARAMS}; diff --git a/src/types/serde_json.rs b/src/types/serde_json.rs index 33cc8f6..54275dd 100644 --- a/src/types/serde_json.rs +++ b/src/types/serde_json.rs @@ -1,5 +1,5 @@ //! `ToSql` and `FromSql` implementation for JSON `Value`. -extern crate serde_json; +use serde_json; use self::serde_json::Value; @@ -8,14 +8,14 @@ use crate::Result; /// Serialize JSON `Value` to text. impl ToSql for Value { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(serde_json::to_string(self).unwrap())) } } /// Deserialize text/blob to JSON `Value`. impl FromSql for Value { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { match value { ValueRef::Text(s) => serde_json::from_str(s), ValueRef::Blob(b) => serde_json::from_slice(b), @@ -46,7 +46,7 @@ mod test { let data: serde_json::Value = serde_json::from_str(json).unwrap(); db.execute( "INSERT INTO foo (t, b) VALUES (?, ?)", - &[&data as &ToSql, &json.as_bytes()], + &[&data as &dyn ToSql, &json.as_bytes()], ) .unwrap(); diff --git a/src/types/time.rs b/src/types/time.rs index 1fd0524..608635f 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -1,4 +1,4 @@ -extern crate time; +use time; use crate::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; use crate::Result; @@ -8,7 +8,7 @@ const SQLITE_DATETIME_FMT: &str = "%Y-%m-%dT%H:%M:%S.%fZ"; const SQLITE_DATETIME_FMT_LEGACY: &str = "%Y-%m-%d %H:%M:%S:%f %Z"; impl ToSql for time::Timespec { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { let time_string = time::at_utc(*self) .strftime(SQLITE_DATETIME_FMT) .unwrap() @@ -18,7 +18,7 @@ impl ToSql for time::Timespec { } impl FromSql for time::Timespec { - fn column_result(value: ValueRef) -> FromSqlResult { + fn column_result(value: ValueRef<'_>) -> FromSqlResult { value .as_str() .and_then(|s| { diff --git a/src/types/to_sql.rs b/src/types/to_sql.rs index 81df0d9..c2ae0cd 100644 --- a/src/types/to_sql.rs +++ b/src/types/to_sql.rs @@ -66,7 +66,7 @@ from_value!(Vec); from_value!(i128); impl<'a> ToSql for ToSqlOutput<'a> { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(match *self { ToSqlOutput::Borrowed(v) => ToSqlOutput::Borrowed(v), ToSqlOutput::Owned(ref v) => ToSqlOutput::Borrowed(ValueRef::from(v)), @@ -81,7 +81,7 @@ impl<'a> ToSql for ToSqlOutput<'a> { /// A trait for types that can be converted into SQLite values. pub trait ToSql { - fn to_sql(&self) -> Result; + fn to_sql(&self) -> Result>; } // We should be able to use a generic impl like this: @@ -99,7 +99,7 @@ pub trait ToSql { macro_rules! to_sql_self( ($t:ty) => ( impl ToSql for $t { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(*self)) } } @@ -125,43 +125,43 @@ impl<'a, T: ?Sized> ToSql for &'a T where T: ToSql, { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { (*self).to_sql() } } impl ToSql for String { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(self.as_str())) } } impl ToSql for str { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(self)) } } impl ToSql for Vec { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(self.as_slice())) } } impl ToSql for [u8] { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(self)) } } impl ToSql for Value { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(self)) } } impl ToSql for Option { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { match *self { None => Ok(ToSqlOutput::from(Null)), Some(ref t) => t.to_sql(), @@ -170,7 +170,7 @@ impl ToSql for Option { } impl<'a> ToSql for Cow<'a, str> { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::from(self.as_ref())) } } diff --git a/src/types/value_ref.rs b/src/types/value_ref.rs index 50f9b17..6da2634 100644 --- a/src/types/value_ref.rs +++ b/src/types/value_ref.rs @@ -70,7 +70,7 @@ impl<'a> ValueRef<'a> { } impl<'a> From> for Value { - fn from(borrowed: ValueRef) -> Value { + fn from(borrowed: ValueRef<'_>) -> Value { match borrowed { ValueRef::Null => Value::Null, ValueRef::Integer(i) => Value::Integer(i), @@ -82,13 +82,13 @@ impl<'a> From> for Value { } impl<'a> From<&'a str> for ValueRef<'a> { - fn from(s: &str) -> ValueRef { + fn from(s: &str) -> ValueRef<'_> { ValueRef::Text(s) } } impl<'a> From<&'a [u8]> for ValueRef<'a> { - fn from(s: &[u8]) -> ValueRef { + fn from(s: &[u8]) -> ValueRef<'_> { ValueRef::Blob(s) } } diff --git a/src/vtab/array.rs b/src/vtab/array.rs index 672e34d..f83f44e 100644 --- a/src/vtab/array.rs +++ b/src/vtab/array.rs @@ -24,7 +24,7 @@ pub(crate) unsafe extern "C" fn free_array(p: *mut c_void) { pub type Array = Rc>; impl ToSql for Array { - fn to_sql(&self) -> Result { + fn to_sql(&self) -> Result> { Ok(ToSqlOutput::Array(self.clone())) } } @@ -129,7 +129,7 @@ impl ArrayTabCursor { } } impl VTabCursor for ArrayTabCursor { - fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values) -> Result<()> { + fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values<'_>) -> Result<()> { if idx_num > 0 { self.ptr = args.get_array(0)?; } else { diff --git a/src/vtab/csvtab.rs b/src/vtab/csvtab.rs index c289843..b67473a 100644 --- a/src/vtab/csvtab.rs +++ b/src/vtab/csvtab.rs @@ -1,7 +1,7 @@ //! CSV Virtual Table. //! //! Port of [csv](http://www.sqlite.org/cgi/src/finfo?name=ext/misc/csv.c) C extension. -extern crate csv; +use csv; use std::fs::File; use std::os::raw::c_int; use std::path::Path; @@ -285,7 +285,12 @@ impl CSVTabCursor { impl VTabCursor for CSVTabCursor { // Only a full table scan is supported. So `filter` simply rewinds to // the beginning. - fn filter(&mut self, _idx_num: c_int, _idx_str: Option<&str>, _args: &Values) -> Result<()> { + fn filter( + &mut self, + _idx_num: c_int, + _idx_str: Option<&str>, + _args: &Values<'_>, + ) -> Result<()> { { let offset_first_row = self.vtab().offset_first_row.clone(); self.reader.seek(offset_first_row)?; diff --git a/src/vtab/mod.rs b/src/vtab/mod.rs index d7cf6e5..b30db51 100644 --- a/src/vtab/mod.rs +++ b/src/vtab/mod.rs @@ -250,7 +250,7 @@ pub struct IndexInfo(*mut ffi::sqlite3_index_info); impl IndexInfo { /// Record WHERE clause constraints. - pub fn constraints(&self) -> IndexConstraintIter { + pub fn constraints(&self) -> IndexConstraintIter<'_> { let constraints = unsafe { slice::from_raw_parts((*self.0).aConstraint, (*self.0).nConstraint as usize) }; IndexConstraintIter { @@ -259,7 +259,7 @@ impl IndexInfo { } /// Information about the ORDER BY clause. - pub fn order_bys(&self) -> OrderByIter { + pub fn order_bys(&self) -> OrderByIter<'_> { let order_bys = unsafe { slice::from_raw_parts((*self.0).aOrderBy, (*self.0).nOrderBy as usize) }; OrderByIter { @@ -272,7 +272,7 @@ impl IndexInfo { unsafe { (*self.0).nOrderBy as usize } } - pub fn constraint_usage(&mut self, constraint_idx: usize) -> IndexConstraintUsage { + pub fn constraint_usage(&mut self, constraint_idx: usize) -> IndexConstraintUsage<'_> { let constraint_usages = unsafe { slice::from_raw_parts_mut((*self.0).aConstraintUsage, (*self.0).nConstraint as usize) }; @@ -412,7 +412,7 @@ impl<'a> OrderBy<'a> { pub trait VTabCursor: Sized { /// Begin a search of a virtual table. /// (See [SQLite doc](https://sqlite.org/vtab.html#the_xfilter_method)) - fn filter(&mut self, idx_num: c_int, idx_str: Option<&str>, args: &Values) -> Result<()>; + fn filter(&mut self, idx_num: c_int, idx_str: Option<&str>, args: &Values<'_>) -> Result<()>; /// Advance cursor to the next row of a result set initiated by `filter`. /// (See [SQLite doc](https://sqlite.org/vtab.html#the_xnext_method)) fn next(&mut self) -> Result<()>; @@ -491,7 +491,7 @@ impl<'a> Values<'a> { } } - pub fn iter(&self) -> ValueIter { + pub fn iter(&self) -> ValueIter<'_> { ValueIter { iter: self.args.iter(), } @@ -575,7 +575,7 @@ impl InnerConnection { } /// Escape double-quote (`"`) character occurences by doubling them (`""`). -pub fn escape_double_quote(identifier: &str) -> Cow { +pub fn escape_double_quote(identifier: &str) -> Cow<'_, str> { if identifier.contains('"') { // escape quote by doubling them Owned(identifier.replace("\"", "\"\"")) diff --git a/src/vtab/series.rs b/src/vtab/series.rs index 716719d..658184a 100644 --- a/src/vtab/series.rs +++ b/src/vtab/series.rs @@ -184,7 +184,7 @@ impl SeriesTabCursor { } } impl VTabCursor for SeriesTabCursor { - fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values) -> Result<()> { + fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values<'_>) -> Result<()> { let idx_num = QueryPlanFlags::from_bits_truncate(idx_num); let mut i = 0; if idx_num.contains(QueryPlanFlags::START) { diff --git a/tests/config_log.rs b/tests/config_log.rs index f4bdd5d..d51acf5 100644 --- a/tests/config_log.rs +++ b/tests/config_log.rs @@ -5,7 +5,6 @@ #[cfg(feature = "trace")] #[macro_use] extern crate lazy_static; -extern crate rusqlite; #[cfg(feature = "trace")] fn main() { diff --git a/tests/deny_single_threaded_sqlite_config.rs b/tests/deny_single_threaded_sqlite_config.rs index 55b6355..288f52a 100644 --- a/tests/deny_single_threaded_sqlite_config.rs +++ b/tests/deny_single_threaded_sqlite_config.rs @@ -1,8 +1,7 @@ //! Ensure we reject connections when SQLite is in single-threaded mode, as it //! would violate safety if multiple Rust threads tried to use connections. -extern crate libsqlite3_sys as ffi; -extern crate rusqlite; +use libsqlite3_sys as ffi; use rusqlite::Connection; diff --git a/tests/vtab.rs b/tests/vtab.rs index 30d4ee7..73d5970 100644 --- a/tests/vtab.rs +++ b/tests/vtab.rs @@ -1,8 +1,5 @@ //! Ensure Virtual tables can be declared outside `rusqlite` crate. -#[cfg(feature = "vtab")] -extern crate rusqlite; - #[cfg(feature = "vtab")] #[test] fn test_dummy_module() { @@ -61,7 +58,7 @@ fn test_dummy_module() { &mut self, _idx_num: c_int, _idx_str: Option<&str>, - _args: &Values, + _args: &Values<'_>, ) -> Result<()> { self.row_id = 1; Ok(()) @@ -98,7 +95,7 @@ fn test_dummy_module() { let mut s = db.prepare("SELECT * FROM dummy()").unwrap(); let dummy = s - .query_row(&[] as &[&ToSql], |row| row.get::<_, i32>(0)) + .query_row(&[] as &[&dyn ToSql], |row| row.get::<_, i32>(0)) .unwrap(); assert_eq!(1, dummy); }