PlanetState

Struct PlanetState 

Source
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

Source

pub fn id(&self) -> ID

Returns the planet id.

Source

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.

Source

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.

Source

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.

Source

pub fn cells_iter(&self) -> Iter<'_, EnergyCell>

Returns an immutable iterator over the energy cells owned by the planet.

Source

pub fn cells_iter_mut(&mut self) -> IterMut<'_, EnergyCell>

Returns a mutable iterator over the energy cells owned by the planet.

Source

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.

Source

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.

Source

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.

Source

pub fn can_have_rocket(&self) -> bool

Returns true if the planet can have a rocket.

Source

pub fn has_rocket(&self) -> bool

Returns true if the planet has a rocket built and ready to launch.

Source

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.

Source

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
Source

pub fn to_dummy(&self) -> DummyPlanetState

Returns a dummy clone of this state.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.