Skip to content

Instantly share code, notes, and snippets.

@teburd
Created October 3, 2017 16:53
Show Gist options
  • Save teburd/981ef0533135715e333a0c803fac976b to your computer and use it in GitHub Desktop.
Save teburd/981ef0533135715e333a0c803fac976b to your computer and use it in GitHub Desktop.
fn sync(&mut self) -> EventResult<()> {
let mut agencies: Vec<&str> = Vec::new();
let mut routes: HashMap<&str, Vec<&str>> = HashMap::new();
let mut stops: HashMap<&str, Vec<&str>> = HashMap::new();
{
for transit in self.transit.iter() {
match transit.as_tuple() {
(agency, "", "") => agencies.push(agency),
(agency, route, "") => {
let mut agency_routes = routes.entry(agency).or_insert(Vec::new());
agency_routes.push(route);
},
(agency, "", stop) => {
let mut agency_stops = stops.entry(agency).or_insert(Vec::new());
agency_stops.push(stop);
}
_ => unreachable!(),
}
}
}
self.transit.clear();
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment