From ece7c041e85a215cfb9c7d15884d11dbf036c087 Mon Sep 17 00:00:00 2001 From: Patrick Fernie Date: Fri, 7 Oct 2016 12:42:27 -0400 Subject: [PATCH 1/3] change query_row* fns to take Row by reference instead of moving --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 50cf7e9..3e3199e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -303,12 +303,12 @@ 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(&self, sql: &str, params: &[&ToSql], f: F) -> Result - where F: FnOnce(Row) -> T + where F: FnOnce(&Row) -> T { let mut stmt = try!(self.prepare(sql)); let mut rows = try!(stmt.query(params)); - rows.get_expected_row().map(f) + rows.get_expected_row().map(|r| f(&r)) } /// Convenience method to execute a query that is expected to return a single row, @@ -339,13 +339,13 @@ impl Connection { params: &[&ToSql], f: F) -> result::Result - where F: FnOnce(Row) -> result::Result, + where F: FnOnce(&Row) -> result::Result, E: convert::From { let mut stmt = try!(self.prepare(sql)); let mut rows = try!(stmt.query(params)); - rows.get_expected_row().map_err(E::from).and_then(f) + rows.get_expected_row().map_err(E::from).and_then(|r| f(&r)) } /// Convenience method to execute a query that is expected to return a single row. @@ -369,7 +369,7 @@ impl Connection { /// does exactly the same thing. #[deprecated(since = "0.1.0", note = "Use query_row instead")] pub fn query_row_safe(&self, sql: &str, params: &[&ToSql], f: F) -> Result - where F: FnOnce(Row) -> T + where F: FnOnce(&Row) -> T { self.query_row(sql, params, f) } From f17fc14a5968432255c60f700dfe25e397b3157d Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Fri, 30 Dec 2016 23:48:04 -0500 Subject: [PATCH 2/3] Update query_row_named so its closure also takes a &Row instead of a Row --- src/named_params.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/named_params.rs b/src/named_params.rs index 7529215..d4a5f47 100644 --- a/src/named_params.rs +++ b/src/named_params.rs @@ -38,12 +38,12 @@ 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 - where F: FnOnce(Row) -> T + where F: FnOnce(&Row) -> T { let mut stmt = try!(self.prepare(sql)); let mut rows = try!(stmt.query_named(params)); - rows.get_expected_row().map(f) + rows.get_expected_row().map(|r| f(&r)) } } From c95c3acc8e2e765a42c5e64b2755f394cce6bbc0 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Fri, 30 Dec 2016 23:48:24 -0500 Subject: [PATCH 3/3] Add breaking change note about Row -> &Row in closures to Changelog --- Changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Changelog.md b/Changelog.md index ea4b6f8..9505465 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,10 @@ methods. * BREAKING CHANGE: The `ToSql` trait has been redesigned. It can now be implemented without `unsafe`, and implementors can choose to return either borrowed or owned results. +* BREAKING CHANGE: The closure passed to `query_row`, `query_row_and_then`, `query_row_safe`, + and `query_row_named` now expects a `&Row` instead of a `Row`. The vast majority of calls + to these functions will probably not need to change; see + https://github.com/jgallagher/rusqlite/pull/184. * Added `#[deprecated(since = "...", note = "...")]` flags (new in Rust 1.9 for libraries) to all deprecated APIs.