Generator

Struct Generator 

Source
pub struct Generator { /* private fields */ }
Expand description

Manages the recipes and production of basic resources for a planet.

The Generator is responsible for storing the allowed recipes for BasicResources and validating creation requests.

Unlike the Combinator, the Generator creates resources “from scratch” (using only energy). To create a basic resource, the generator:

  1. Checks if the requested resource type is in its set of allowed recipes.
  2. Discharges the provided EnergyCell to power the generation process.

Each planet instance has its own Generator initialized with a specific set of rules.

Implementations§

Source§

impl Generator

Source

pub fn new() -> Generator

Creates a new Generator with no recipes.

Source

pub fn contains(&self, basic: BasicResourceType) -> bool

Returns true if the Generator contains a recipe for the specified BasicResourceType.

Source

pub fn all_available_recipes(&self) -> HashSet<BasicResourceType>

Returns a HashSet of all the recipes available in the Generator.

Source§

impl Generator

Source

pub fn make_oxygen( &self, energy_cell: &mut EnergyCell, ) -> Result<Oxygen, String>

Creates a new [<$basic>] resource.

This method attempts to create a new instance of the corresponding basic resource by discharging an EnergyCell.

§Arguments
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

  • Ok([<$basic>]): The resource was successfully created.
§Errors

Returns an error if there is no recipe for this resource or if the energy_cell is not charged.

Source

pub fn make_hydrogen( &self, energy_cell: &mut EnergyCell, ) -> Result<Hydrogen, String>

Creates a new [<$basic>] resource.

This method attempts to create a new instance of the corresponding basic resource by discharging an EnergyCell.

§Arguments
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

  • Ok([<$basic>]): The resource was successfully created.
§Errors

Returns an error if there is no recipe for this resource or if the energy_cell is not charged.

Source

pub fn make_carbon( &self, energy_cell: &mut EnergyCell, ) -> Result<Carbon, String>

Creates a new [<$basic>] resource.

This method attempts to create a new instance of the corresponding basic resource by discharging an EnergyCell.

§Arguments
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

  • Ok([<$basic>]): The resource was successfully created.
§Errors

Returns an error if there is no recipe for this resource or if the energy_cell is not charged.

Source

pub fn make_silicon( &self, energy_cell: &mut EnergyCell, ) -> Result<Silicon, String>

Creates a new [<$basic>] resource.

This method attempts to create a new instance of the corresponding basic resource by discharging an EnergyCell.

§Arguments
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

  • Ok([<$basic>]): The resource was successfully created.
§Errors

Returns an error if there is no recipe for this resource or if the energy_cell is not charged.

Source

pub fn try_make( &self, req: BasicResourceType, energy_cell: &mut EnergyCell, ) -> Result<BasicResource, String>

Attempts to create a basic resource of the specified type.

This method provides a generic way to request the creation of any basic resource that the generator has a recipe for.

§Arguments
  • req - The BasicResourceType enum variant representing the desired resource.
  • energy_cell - A mutable reference to an EnergyCell to be used for discharging during resource creation.
§Returns

A Result indicating success:

  • Ok(BasicResource): The requested resource was successfully created and wrapped in the BasicResource enum.
§Errors

Returns an error if the energy_cell is not charged or if there is no recipe for the requested resource type.

Trait Implementations§

Source§

impl Debug for Generator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Generator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.