diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 24b0e7e..eca404b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -8,3 +8,4 @@ rusqlite contributors (sorted alphabetically) * [Huon Wilson](https://github.com/huonw) * [Patrick Fernie](https://github.com/pfernie) * [Steve Klabnik](https://github.com/steveklabnik) +* [krdln](https://github.com/krdln) diff --git a/Cargo.toml b/Cargo.toml index 0078216..673c8ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ trace = [] [dependencies] time = "~0.1.0" bitflags = "~0.1" -libc = "~0.1" +libc = "~0.2" [dev-dependencies] tempdir = "~0.3.4" diff --git a/Changelog.md b/Changelog.md index 5a1eaec..f0b36e5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,9 @@ # Version UPCOMING (TBD) * Adds `trace` feature that allows the use of SQLite's logging, tracing, and profiling hooks. +* Slight change to the closure types passed to `query_map` and `query_and_then`: + * Remove the `'static` requirement on the closure's output type. + * Give the closure a `&SqliteRow` instead of a `SqliteRow`. # Version 0.4.0 (2015-11-03) diff --git a/README.md b/README.md index 990af8d..1bc6742 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ There are other, less obvious things that may result in a panic as well, such as `collect()` on a `SqliteRows` and then trying to use the collected rows. Strongly consider using the method `query_map()` instead, if you can. -`query_map()` returns an iterator over rows-mapped-to-some-`'static`-type. This +`query_map()` returns an iterator over rows-mapped-to-some-type. This iterator does not have any of the above issues with panics due to attempting to access stale rows. diff --git a/libsqlite3-sys/Cargo.toml b/libsqlite3-sys/Cargo.toml index ecb20b8..cafa632 100644 --- a/libsqlite3-sys/Cargo.toml +++ b/libsqlite3-sys/Cargo.toml @@ -15,4 +15,4 @@ load_extension = [] pkg-config = "~0.3" [dependencies] -libc = "~0.1" +libc = "~0.2" diff --git a/src/lib.rs b/src/lib.rs index cd24ad9..de5dc00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -705,8 +705,7 @@ impl<'conn> SqliteStatement<'conn> { /// for accessing stale rows. pub fn query_map<'a, T, F>(&'a mut self, params: &[&ToSql], f: F) -> SqliteResult> - where T: 'static, - F: FnMut(SqliteRow) -> T { + where F: FnMut(&SqliteRow) -> T { let row_iter = try!(self.query(params)); Ok(MappedRows{ @@ -723,9 +722,8 @@ impl<'conn> SqliteStatement<'conn> { /// for accessing stale rows. pub fn query_and_then<'a, T, E, F>(&'a mut self, params: &[&ToSql], f: F) -> SqliteResult> - where T: 'static, - E: convert::From, - F: FnMut(SqliteRow) -> Result { + where E: convert::From, + F: FnMut(&SqliteRow) -> Result { let row_iter = try!(self.query(params)); Ok(AndThenRows{ @@ -797,12 +795,11 @@ pub struct MappedRows<'stmt, F> { } impl<'stmt, T, F> Iterator for MappedRows<'stmt, F> - where T: 'static, - F: FnMut(SqliteRow) -> T { + where F: FnMut(&SqliteRow) -> T { type Item = SqliteResult; fn next(&mut self) -> Option> { - self.rows.next().map(|row_result| row_result.map(|row| (self.map)(row))) + self.rows.next().map(|row_result| row_result.map(|row| (self.map)(&row))) } } @@ -814,15 +811,14 @@ pub struct AndThenRows<'stmt, F> { } impl<'stmt, T, E, F> Iterator for AndThenRows<'stmt, F> - where T: 'static, - E: convert::From, - F: FnMut(SqliteRow) -> Result { + where E: convert::From, + F: FnMut(&SqliteRow) -> Result { type Item = Result; fn next(&mut self) -> Option { self.rows.next().map(|row_result| row_result .map_err(E::from) - .and_then(|row| (self.map)(row))) + .and_then(|row| (self.map)(&row))) } }