Skip to content

Instantly share code, notes, and snippets.

@shubhamkumar13
Created October 5, 2022 10:41
Show Gist options
  • Save shubhamkumar13/04e824f045f658e79c7d5148fd874b61 to your computer and use it in GitHub Desktop.
Save shubhamkumar13/04e824f045f658e79c7d5148fd874b61 to your computer and use it in GitHub Desktop.
before_wrong_code
// find the nearest cab in the fleet from the person
let mut nearest_cab = fleet
.into_iter()
.reduce(|c1, c2| person.nearest_cab(&c1, &c2))
.and_then(|x| Some(x.clone()))
.expect("Unable to get the nearest cab");
// check if the cab is assigned or not
match is_free(nearest_cab.clone()) {
Ok(_) => {
// update cab destination and person_id
nearest_cab.update_destination(Some(person.location.clone()));
nearest_cab.update_person_id(ObjectId::parse_str(person_id).ok());
// update cab by using `assign_person`
....
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment