Advertisement
cwchen

[Rust] Retrieving data from a map

Aug 23rd, 2017
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.30 KB | None | 0 0
  1. use std::collections::HashMap;
  2.  
  3. fn main() {
  4.     let mut hash = HashMap::new();
  5.  
  6.     hash.insert("one", "eins");
  7.     hash.insert("two", "zwei");
  8.     hash.insert("three", "drei");
  9.  
  10.     let data = match hash.get("one") {
  11.         None => "",
  12.         Some(v) => *v
  13.     };
  14.     assert_eq!(data, "eins");
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement