Skip to main content

AssetRef

Struct AssetRef 

Source
pub struct AssetRef(Rc<Asset>);
Expand description

A wrapper containing a reference-counted Asset.

AssetRef implements equality, ordering, and hashing using an AssetID, if available, but otherwise using a combination of other fields which should be unique at all the relevant points in the simulation.

Tuple Fields§

§0: Rc<Asset>

Implementations§

Source§

impl AssetRef

Source

pub fn make_mut(&mut self) -> &mut Asset

Make a mutable reference to the underlying Asset

Source

fn get_asset_cmp(&self) -> AssetCmp<'_>

Get a representation of this AssetRef that can be used for comparisons

Source

pub fn with_subset_of_units(self, new_num_units: u32) -> Self

Get an AssetRef representing a subset of this asset’s units.

For non-divisible assets, new_num_units must be one. If some of the asset’s units are mothballed, these are discarded before non-mothballed units. For example, if an asset has seven units of which four are mothballed and we are reducing the number of units to four, the new asset will have one mothballed unit.

§Panics

Panics if new_num_units is zero or exceeds the total capacity of this asset.

Source

fn decommission(self, reason: &str)

Decommission this asset

Source

fn with_decommission_mothballed( self, year: u32, mothball_years: u32, ) -> Option<Self>

Decommission any units that were mothballed at least mothball_years ago.

If the asset still has some units remaining, it is returned, else None.

Source

pub fn with_mothballed_units(self, num_units: u32, year: Option<u32>) -> Self

Return a new AssetRef with the specified number of units mothballed.

If num_units equals the number of already mothballed units, the original asset is returned. If additional units may be mothballed, a value must be provided for year.

§Panics

Panics if attempting to mothball more units than the asset represents or if attempting to change the number of mothballed units for a non-commissioned asset.

Source

pub fn with_no_mothballed_units(self) -> Self

Returns a new AssetRef with no mothballed units.

If the asset has no mothballed units, the original asset is returned.

Trait Implementations§

Source§

impl Clone for AssetRef

Source§

fn clone(&self) -> AssetRef

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AssetRef

Source§

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

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

impl Deref for AssetRef
where Rc<Asset>: Deref,

Source§

type Target = <Rc<Asset> as Deref>::Target

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<Asset> for AssetRef

Source§

fn from(value: Asset) -> Self

Converts to this type from the input type.
Source§

impl From<AssetRef> for Rc<Asset>

Source§

fn from(value: AssetRef) -> Self

Converts to this type from the input type.
Source§

impl From<Rc<Asset>> for AssetRef

Source§

fn from(value: Rc<Asset>) -> Self

Converts to this type from the input type.
Source§

impl From<UserAsset> for AssetRef

Source§

fn from(value: UserAsset) -> Self

Converts to this type from the input type.
Source§

impl Hash for AssetRef

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for AssetRef

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for AssetRef

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for AssetRef

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for AssetRef

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.