SHARE
TWEET

Untitled

a guest Apr 26th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top