Created
November 7, 2019 22:18
-
-
Save rust-play/c6051b7ed614b4efe79df58cc71a62e0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get by struct | |
use std::collections::HashSet; | |
#[derive(Hash, Eq, PartialEq, Debug)] | |
struct City { | |
name: String, | |
population: usize, | |
} | |
fn main() { | |
let mut cities = HashSet::new(); | |
cities.insert(City { | |
name: "San Francisco".to_string(), | |
population: 884_363, | |
}); | |
cities.insert(City { | |
name: "Tokyo".to_string(), | |
population: 9_273_000, | |
}); | |
cities.insert(City { | |
name: "Hong Kong".to_string(), | |
population: 7_392_000, | |
}); | |
println!( | |
"{:#?}", | |
&cities.get(&City { | |
name: "San Francisco".to_string(), | |
population: 884_363 | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment