Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 7, 2019 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rust-play/c6051b7ed614b4efe79df58cc71a62e0 to your computer and use it in GitHub Desktop.
Save rust-play/c6051b7ed614b4efe79df58cc71a62e0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
// 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