Combinator

Struct Combinator 

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

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

The Combinator is responsible for storing the allowed recipes for ComplexResources and validating creation requests.

It works in conjunction with an EnergyCell. To create a complex resource, the combinator:

  1. Checks if the requested resource type is in its set of allowed recipes.
  2. Consumes the required input resources.
  3. Discharges the provided EnergyCell to power the combination process.

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

Implementations§

Source§

impl Combinator

Source

pub fn new() -> Combinator

Creates a new Combinator with no recipes.

Source

pub fn contains(&self, complex: ComplexResourceType) -> bool

Returns true if the Combinator contains a recipe for the specified ComplexResourceType.

Source

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

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

Source§

impl Combinator

Source

pub fn make_water( &self, r1: Hydrogen, r2: Oxygen, energy_cell: &mut EnergyCell, ) -> Result<Water, (String, Hydrogen, Oxygen)>

Creates a new [<$result>] resource.

This method attempts to create a new instance of the corresponding complex resource by combining two input resources (r1 and r2) and discharging an EnergyCell.

§Arguments
  • r1 - The first input resource ([$lhs]).
  • r2 - The second input resource ([$rhs]).
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

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

Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.

Source

pub fn make_diamond( &self, r1: Carbon, r2: Carbon, energy_cell: &mut EnergyCell, ) -> Result<Diamond, (String, Carbon, Carbon)>

Creates a new [<$result>] resource.

This method attempts to create a new instance of the corresponding complex resource by combining two input resources (r1 and r2) and discharging an EnergyCell.

§Arguments
  • r1 - The first input resource ([$lhs]).
  • r2 - The second input resource ([$rhs]).
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

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

Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.

Source

pub fn make_life( &self, r1: Water, r2: Carbon, energy_cell: &mut EnergyCell, ) -> Result<Life, (String, Water, Carbon)>

Creates a new [<$result>] resource.

This method attempts to create a new instance of the corresponding complex resource by combining two input resources (r1 and r2) and discharging an EnergyCell.

§Arguments
  • r1 - The first input resource ([$lhs]).
  • r2 - The second input resource ([$rhs]).
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

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

Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.

Source

pub fn make_robot( &self, r1: Silicon, r2: Life, energy_cell: &mut EnergyCell, ) -> Result<Robot, (String, Silicon, Life)>

Creates a new [<$result>] resource.

This method attempts to create a new instance of the corresponding complex resource by combining two input resources (r1 and r2) and discharging an EnergyCell.

§Arguments
  • r1 - The first input resource ([$lhs]).
  • r2 - The second input resource ([$rhs]).
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

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

Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.

Source

pub fn make_dolphin( &self, r1: Water, r2: Life, energy_cell: &mut EnergyCell, ) -> Result<Dolphin, (String, Water, Life)>

Creates a new [<$result>] resource.

This method attempts to create a new instance of the corresponding complex resource by combining two input resources (r1 and r2) and discharging an EnergyCell.

§Arguments
  • r1 - The first input resource ([$lhs]).
  • r2 - The second input resource ([$rhs]).
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

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

Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.

Source

pub fn make_aipartner( &self, r1: Robot, r2: Diamond, energy_cell: &mut EnergyCell, ) -> Result<AIPartner, (String, Robot, Diamond)>

Creates a new [<$result>] resource.

This method attempts to create a new instance of the corresponding complex resource by combining two input resources (r1 and r2) and discharging an EnergyCell.

§Arguments
  • r1 - The first input resource ([$lhs]).
  • r2 - The second input resource ([$rhs]).
  • energy_cell - A mutable reference to an EnergyCell which will be discharged to create the resource.
§Returns

A Result indicating success:

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

Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.

Source

pub fn try_make( &self, req: ComplexResourceRequest, energy_cell: &mut EnergyCell, ) -> Result<ComplexResource, (String, GenericResource, GenericResource)>

Attempts to create a complex resource based on a given request.

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

§Arguments
  • req - The ComplexResourceRequest enum variant representing the desired complex resource and its required input resources.
  • energy_cell - A mutable reference to an EnergyCell which will be discharged during resource creation.
§Returns

A Result indicating success:

  • Ok(ComplexResource): The complex resource was successfully created.
§Errors

Returns an error if there is no recipe for the requested complex resource or if the energy cell discharge fails. The input resources are returned in the error tuple to prevent ownership loss on failure.

Trait Implementations§

Source§

impl Debug for Combinator

Source§

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

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

impl Default for Combinator

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.