Skip to content

Instantly share code, notes, and snippets.

Created June 19, 2015 08:44
Show Gist options
  • Save anonymous/6a6b50ebf589fcce1dbf to your computer and use it in GitHub Desktop.
Save anonymous/6a6b50ebf589fcce1dbf to your computer and use it in GitHub Desktop.
Shared via Rust Playground
use std::collections::HashMap;
struct User {
reference: String,
email: String
}
fn main() {
let mut users: HashMap<String, User> = HashMap::new();
users.insert("first".to_string(), User { reference: "ref1".to_string(), email: "test@test.com".to_string() });
users.insert("second".to_string(), User { reference: "ref2".to_string(), email: "test1@test.com".to_string() });
users.insert("third".to_string(), User { reference: "ref3".to_string(), email: "test3@test.com".to_string() });
//this is my failed attempt
let user_refs: Vec<String> = users.iter().map(|(_, user)| user.reference.clone()).collect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment