Update query_row_named so its closure also takes a &Row instead of a Row

This commit is contained in:
John Gallagher 2016-12-30 23:48:04 -05:00
parent 3815b6beef
commit f17fc14a59

View File

@ -38,12 +38,12 @@ impl Connection {
/// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the /// Will return `Err` if `sql` cannot be converted to a C-compatible string or if the
/// underlying SQLite call fails. /// underlying SQLite call fails.
pub fn query_row_named<T, F>(&self, sql: &str, params: &[(&str, &ToSql)], f: F) -> Result<T> pub fn query_row_named<T, F>(&self, sql: &str, params: &[(&str, &ToSql)], f: F) -> Result<T>
where F: FnOnce(Row) -> T where F: FnOnce(&Row) -> T
{ {
let mut stmt = try!(self.prepare(sql)); let mut stmt = try!(self.prepare(sql));
let mut rows = try!(stmt.query_named(params)); let mut rows = try!(stmt.query_named(params));
rows.get_expected_row().map(f) rows.get_expected_row().map(|r| f(&r))
} }
} }