Skip to content

Instantly share code, notes, and snippets.

@sgrif
Created April 17, 2016 18:35
Show Gist options
  • Save sgrif/68cbba9a87084da3a2e8c42a12e7d6cf to your computer and use it in GitHub Desktop.
Save sgrif/68cbba9a87084da3a2e8c42a12e7d6cf to your computer and use it in GitHub Desktop.
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())
}
}
if cache.contains_key(&sql) {
Ok(cache[&sql].clone())
} else {
let statement = try!(Statement::prepare(&self.raw_connection, &sql));
let entry = cache.entry(sql);
Ok(entry.or_insert(CachedStatement::new(statement)).clone())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment