pub struct PlanetState { /* private fields */ }Expand description
This struct is a representation of the internal state of the planet. Through its public methods, it gives access to the energy cells and rocket construction of the planet.
Implementations§
Source§impl PlanetState
impl PlanetState
Sourcepub fn cell(&self, i: usize) -> &EnergyCell
pub fn cell(&self, i: usize) -> &EnergyCell
Indexed getter accessor for the EnergyCell vec.
§Returns
An immutable borrow of the i-th energy cell.
§Panics
This method will panic if the index i is out of bounds.
Always check the number of energy cells available with PlanetState::cells_count.
Sourcepub fn cell_mut(&mut self, i: usize) -> &mut EnergyCell
pub fn cell_mut(&mut self, i: usize) -> &mut EnergyCell
Indexed mutable getter accessor for the EnergyCell vec.
§Returns
An mutable borrow of the i-th energy cell.
§Panics
This method will panic if the index i is out of bounds.
Always check the number of energy cells available with PlanetState::cells_count.
Sourcepub fn cells_count(&self) -> usize
pub fn cells_count(&self) -> usize
Returns the number of energy cells owned by the planet. This is the actual size of the internal vec containing the cells.
Sourcepub fn cells_iter(&self) -> Iter<'_, EnergyCell>
pub fn cells_iter(&self) -> Iter<'_, EnergyCell>
Returns an immutable iterator over the energy cells owned by the planet.
Sourcepub fn cells_iter_mut(&mut self) -> IterMut<'_, EnergyCell>
pub fn cells_iter_mut(&mut self) -> IterMut<'_, EnergyCell>
Returns a mutable iterator over the energy cells owned by the planet.
Sourcepub fn charge_cell(&mut self, sunray: Sunray) -> Option<Sunray>
pub fn charge_cell(&mut self, sunray: Sunray) -> Option<Sunray>
Charges the first empty (discharged) cell. Returns an optional Sunray if there’s no cell to charge.
Sourcepub fn empty_cell(&mut self) -> Option<(&mut EnergyCell, usize)>
pub fn empty_cell(&mut self) -> Option<(&mut EnergyCell, usize)>
Returns a tuple containing a mutable borrow of the first empty (discharged) cell
and its index, or None if there isn’t any.
Sourcepub fn full_cell(&mut self) -> Option<(&mut EnergyCell, usize)>
pub fn full_cell(&mut self) -> Option<(&mut EnergyCell, usize)>
Returns a tuple containing a mutable borrow of the first full (charged) cell
and its index, or None if there isn’t any.
Sourcepub fn can_have_rocket(&self) -> bool
pub fn can_have_rocket(&self) -> bool
Returns true if the planet can have a rocket.
Sourcepub fn has_rocket(&self) -> bool
pub fn has_rocket(&self) -> bool
Returns true if the planet has a rocket built and ready to launch.
Sourcepub fn take_rocket(&mut self) -> Option<Rocket>
pub fn take_rocket(&mut self) -> Option<Rocket>
Takes the rocket out of the planet state (if there is one), leaving
None in its place.
Sourcepub fn build_rocket(&mut self, i: usize) -> Result<(), String>
pub fn build_rocket(&mut self, i: usize) -> Result<(), String>
Constructs a rocket using the i-th EnergyCell of the planet and stores it
inside the planet, taking ownership of it.
§Panics
This method will panic if the index i is out of bounds.
Always check the number of energy cells available with PlanetState::cells_count.
§Errors
Returns an error if:
- The planet type prohibits the storing of rockets.
- The planet already has a rocket built.
- The energy cell is not charged
Sourcepub fn to_dummy(&self) -> DummyPlanetState
pub fn to_dummy(&self) -> DummyPlanetState
Returns a dummy clone of this state.