Resource

Struct Resource 

Source
pub struct Resource<Content: 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<Content: ResourceType> Resource<Content>

Source

pub fn empty() -> Self

Creates a new empty Resource.

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 split_off( &mut self, amount: u32, ) -> Result<Self, InsufficientResourceError<Content>>

Removes a specified amount of resources from this Resource and returns them as a new Resource. If there are insufficient resources in the Resource, it returns None.

Source

pub fn add_bundle<const AMOUNT: u32>(&mut self, bundle: Bundle<Content, 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, ) -> Result<Bundle<Content, AMOUNT>, InsufficientResourceError<Content>>

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

Trait Implementations§

Source§

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

Source§

type Output = Resource<Content>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

type Output = Resource<Content>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<Content: ResourceType> Add for Resource<Content>

Source§

type Output = Resource<Content>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

fn add_assign(&mut self, bundle: Bundle<Content, AMOUNT>)

Performs the += operation. Read more
Source§

impl<Content: ResourceType> AddAssign for Resource<Content>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<Content: Debug + ResourceType> Debug for Resource<Content>

Source§

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

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

impl<Content: ResourceType> Display for Resource<Content>

Source§

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

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

impl<Content: ResourceType, const AMOUNT: u32> From<Bundle<Content, AMOUNT>> for Resource<Content>

Source§

fn from(bundle: Bundle<Content, AMOUNT>) -> Self

Converts to this type from the input type.
Source§

impl<Content: Ord + ResourceType> Ord for Resource<Content>

Source§

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

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

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

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

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

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

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

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

impl<Content: ResourceType> PartialEq<Resource<Content>> for u32

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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<Content: ResourceType> PartialEq<u32> for Resource<Content>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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<Content: PartialEq + ResourceType> PartialEq for Resource<Content>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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<Content: ResourceType> PartialOrd<Resource<Content>> for u32

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

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

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

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§

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

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

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<Content: ResourceType> PartialOrd<u32> for Resource<Content>

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§

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

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

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§

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

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

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<Content: PartialOrd + ResourceType> PartialOrd for Resource<Content>

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

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

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

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§

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

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

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<Content: Eq + ResourceType> Eq for Resource<Content>

Source§

impl<Content: ResourceType> StructuralPartialEq for Resource<Content>

Auto Trait Implementations§

§

impl<Content> Freeze for Resource<Content>

§

impl<Content> RefUnwindSafe for Resource<Content>
where Content: RefUnwindSafe,

§

impl<Content> Send for Resource<Content>
where Content: Send,

§

impl<Content> Sync for Resource<Content>
where Content: Sync,

§

impl<Content> Unpin for Resource<Content>
where Content: Unpin,

§

impl<Content> UnwindSafe for Resource<Content>
where Content: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.