Created
January 13, 2015 13:57
-
-
Save marcusklaas/276ffeb0e6025b36866f to your computer and use it in GitHub Desktop.
Copy trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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