Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. use std::collections::HashMap;
  2.  
  3. fn read_with_cache<'a>(
  4. storage: &HashMap<Vec<u8>, Vec<u8>>,
  5. cache: &'a mut HashMap<Vec<u8>, Vec<u8>>,
  6. key: &Vec<u8>,
  7. ) -> Option<&'a Vec<u8>> {
  8.  
  9. if let Some(res) = cache.get(key) {
  10. return Some(res);
  11. }
  12.  
  13. if let Some(data) = storage.get(key) {
  14. cache.insert(key.to_vec(), data.to_vec());
  15. return cache.get(key);
  16. }
  17. None
  18. }
  19.  
  20. fn main() {
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement