Skip to content

Instantly share code, notes, and snippets.

@marcusklaas
Created January 13, 2015 13:57
Show Gist options
  • Save marcusklaas/276ffeb0e6025b36866f to your computer and use it in GitHub Desktop.
Save marcusklaas/276ffeb0e6025b36866f to your computer and use it in GitHub Desktop.
Copy trait
pub fn query_and_collect<T, F, C>(&self, sql: &str, params: &[&ToSql], f: F) -> SqliteResult<C>
where F: Fn(SqliteRow) -> T + Copy, // FIXME: is the Copy really necessary?
C: FromIterator<T> {
let mut statement = try!(self.prepare(sql));
statement
.query(params)
.and_then(|rows| {
rows
.map(|row| {
row.map(f)
})
.collect()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment