Resource

Struct Resource 

Source
pub struct Resource<const RESOURCE_TYPE: ResourceType> { /* private fields */ }
Expand description

Holds an arbitrary amount of a resource. A Resource object can be split into smaller parts, combined or Bundles can be extracted from them.

Implementations§

Source§

impl<const RESOURCE_TYPE: ResourceType> Resource<RESOURCE_TYPE>

Source

pub fn empty() -> Self

Creates a new empty Resource.

Source

pub fn resource_type(&self) -> ResourceType

Source

pub fn amount(&self) -> u32

The current amount of the resource contained in this Resource.

Source

pub fn split(self, amount: u32) -> Result<(Self, Self), Self>

Splits the Resource into two smaller parts. If there are insufficient resources in the Resource, it returns an error with the original resource.

Source

pub fn add_bundle<const AMOUNT: u32>( &mut self, bundle: Bundle<RESOURCE_TYPE, AMOUNT>, )

Consumes a Bundle of the same resource type and adds the contained resources to this Resource.

Source

pub fn bundle<const AMOUNT: u32>( &mut self, ) -> Option<Bundle<RESOURCE_TYPE, AMOUNT>>

Takes a specified amount of resources from this Resource and puts it into a Bundle.

Trait Implementations§

Source§

impl<const RESOURCE_TYPE: ResourceType, const AMOUNT: u32> Add<Bundle<RESOURCE_TYPE, AMOUNT>> for Resource<RESOURCE_TYPE>

Source§

type Output = Resource<RESOURCE_TYPE>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Bundle<RESOURCE_TYPE, AMOUNT>) -> Self::Output

Performs the + operation. Read more
Source§

impl<const RESOURCE_TYPE: ResourceType, const AMOUNT: u32> Add<Resource<RESOURCE_TYPE>> for Bundle<RESOURCE_TYPE, AMOUNT>

Source§

type Output = Resource<RESOURCE_TYPE>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Resource<RESOURCE_TYPE>) -> Self::Output

Performs the + operation. Read more
Source§

impl<const RESOURCE_TYPE: ResourceType> Add for Resource<RESOURCE_TYPE>

Source§

type Output = Resource<RESOURCE_TYPE>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<const RESOURCE_TYPE: ResourceType, const AMOUNT: u32> AddAssign<Bundle<RESOURCE_TYPE, AMOUNT>> for Resource<RESOURCE_TYPE>

Source§

fn add_assign(&mut self, _bundle: Bundle<RESOURCE_TYPE, AMOUNT>)

Performs the += operation. Read more
Source§

impl<const RESOURCE_TYPE: ResourceType> AddAssign for Resource<RESOURCE_TYPE>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const RESOURCE_TYPE: ResourceType> Debug for Resource<RESOURCE_TYPE>

Source§

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

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

impl<const RESOURCE_TYPE: ResourceType> Display for Resource<RESOURCE_TYPE>

Source§

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

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

impl<const RESOURCE_TYPE: ResourceType> Ord for Resource<RESOURCE_TYPE>

Source§

fn cmp(&self, other: &Resource<RESOURCE_TYPE>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl<const RESOURCE_TYPE: ResourceType> PartialEq<Resource<RESOURCE_TYPE>> for u32

Source§

fn eq(&self, other: &Resource<RESOURCE_TYPE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<const RESOURCE_TYPE: ResourceType> PartialEq<u32> for Resource<RESOURCE_TYPE>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<const RESOURCE_TYPE: ResourceType> PartialEq for Resource<RESOURCE_TYPE>

Source§

fn eq(&self, other: &Resource<RESOURCE_TYPE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<const RESOURCE_TYPE: ResourceType> PartialOrd<Resource<RESOURCE_TYPE>> for u32

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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<const RESOURCE_TYPE: ResourceType> PartialOrd<u32> for Resource<RESOURCE_TYPE>

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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<const RESOURCE_TYPE: ResourceType> PartialOrd for Resource<RESOURCE_TYPE>

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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<const RESOURCE_TYPE: ResourceType> Eq for Resource<RESOURCE_TYPE>

Source§

impl<const RESOURCE_TYPE: ResourceType> StructuralPartialEq for Resource<RESOURCE_TYPE>

Auto Trait Implementations§

§

impl<const RESOURCE_TYPE: ResourceType> Freeze for Resource<RESOURCE_TYPE>

§

impl<const RESOURCE_TYPE: ResourceType> RefUnwindSafe for Resource<RESOURCE_TYPE>

§

impl<const RESOURCE_TYPE: ResourceType> Send for Resource<RESOURCE_TYPE>

§

impl<const RESOURCE_TYPE: ResourceType> Sync for Resource<RESOURCE_TYPE>

§

impl<const RESOURCE_TYPE: ResourceType> Unpin for Resource<RESOURCE_TYPE>

§

impl<const RESOURCE_TYPE: ResourceType> UnwindSafe for Resource<RESOURCE_TYPE>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.