Gets this unit from space or the current planet. NoSuchUnit - the unit does not exist.
(&self, id: UnitID)
| 813 | /// |
| 814 | /// * NoSuchUnit - the unit does not exist. |
| 815 | fn get_unit(&self, id: UnitID) -> Result<&Unit, GameError> { |
| 816 | if let Some(unit) = self.get_planet(Planet::Earth).units.get(&id) { |
| 817 | Ok(unit) |
| 818 | } else if let Some(unit) = self.get_planet(Planet::Mars).units.get(&id) { |
| 819 | Ok(unit) |
| 820 | } else if let Some(unit) = self.get_team(Team::Red).units_in_space.get(&id) { |
| 821 | Ok(unit) |
| 822 | } else if let Some(unit) = self.get_team(Team::Blue).units_in_space.get(&id) { |
| 823 | Ok(unit) |
| 824 | } else { |
| 825 | Err(GameError::NoSuchUnit)? |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | /// Gets a mutable version of this unit from space or the current planet. |
| 830 | /// |
no test coverage detected