Struct AssetPool

Source
pub struct AssetPool {
    assets: Vec<Asset>,
    current_year: u32,
}
Expand description

A pool of Assets

Fields§

§assets: Vec<Asset>

The pool of assets, both active and yet to be commissioned.

Sorted in order of commission year.

§current_year: u32

Current milestone year.

Implementations§

Source§

impl AssetPool

Source

pub fn new(assets: Vec<Asset>) -> Self

Create a new AssetPool

Source

pub fn commission_new(&mut self, year: u32)

Commission new assets for the specified milestone year

Source

pub fn decomission_old(&mut self, year: u32)

Decommission old assets for the specified milestone year

Source

pub fn get(&self, id: AssetID) -> Option<&Asset>

Get an asset with the specified ID.

§Returns

Reference to an Asset if found, else None. The asset may not be found if it has already been decommissioned.

Source

pub fn iter(&self) -> impl Iterator<Item = &Asset>

Iterate over active assets

Source

pub fn iter_for_region<'a>( &'a self, region_id: &'a RegionID, ) -> impl Iterator<Item = &'a Asset>

Iterate over active assets for a particular region

Source

pub fn iter_for_region_and_commodity<'a>( &'a self, region_id: &'a RegionID, commodity: &'a Rc<Commodity>, ) -> impl Iterator<Item = &'a Asset>

Iterate over only the active assets in a given region that produce or consume a given commodity

Source

pub fn retain(&mut self, assets_to_keep: &HashSet<AssetID>)

Retain all assets whose IDs are in assets_to_keep.

Other assets will be decommissioned. Assets which have not yet been commissioned will not be affected.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.