Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- fn read_with_cache<'a>(
- storage: &HashMap<Vec<u8>, Vec<u8>>,
- cache: &'a mut HashMap<Vec<u8>, Vec<u8>>,
- key: &Vec<u8>,
- ) -> Option<&'a Vec<u8>> {
- if let Some(res) = cache.get(key) {
- return Some(res);
- }
- if let Some(data) = storage.get(key) {
- cache.insert(key.to_vec(), data.to_vec());
- return cache.get(key);
- }
- None
- }
- fn main() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement