Skip to content

Instantly share code, notes, and snippets.

@sgrif
Created April 30, 2016 19:12
Show Gist options
  • Save sgrif/95bdbd302124010a0e4dbc39862313f2 to your computer and use it in GitHub Desktop.
Save sgrif/95bdbd302124010a0e4dbc39862313f2 to your computer and use it in GitHub Desktop.
cache.entry(sql).or_insert_with_result(|sql| {
Statement::prepare(&self.raw_connection, &sql)
.map(CachedStatement::new)
}).clone()
match cache.entry(sql) {
Occupied(entry) => Ok(entry.get().clone()),
Vacant(entry) => {
let statement = try!(Statement::prepare(&self.raw_connection, entry.key()));
Ok(entry.insert(CachedStatement::new(statement)).clone())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment