Resource

Struct Resource 

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

Source

pub const fn new_empty() -> Resource<Content>

Creates a new empty Resource.

Source

pub const fn amount(&self) -> u32

The current amount of the resource contained in this Resource.

Source

pub const fn split( self, amount: u32, ) -> Result<(Resource<Content>, Resource<Content>), Resource<Content>>

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 const fn split_off( &mut self, amount: u32, ) -> Result<Resource<Content>, 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 const fn split_off_max(&mut self, amount: u32) -> Resource<Content>

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

Source

pub const fn empty(&mut self) -> Resource<Content>

Empties this Resource, returning all contained resources as a new Resource.

Source

pub const fn empty_except(&mut self, amount: u32) -> Resource<Content>

Empties this Resource except for the specified amount, returning the emptied resources as a new Resource.

Source

pub const fn empty_into(&mut self, other: &mut Resource<Content>)

Empties this Resource into another Resource, transferring all contained resources.

Source

pub fn add(&mut self, other: impl Into<Resource<Content>>)

Adds the entire contents of another resource container to this one.

Source

pub const 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 const 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, const AMOUNT: u32> Add<Bundle<Content, AMOUNT>> for Resource<Content>
where Content: ResourceType,

Source§

type Output = Resource<Content>

The resulting type after applying the + operator.
Source§

fn add( self, rhs: Bundle<Content, AMOUNT>, ) -> <Resource<Content> as Add<Bundle<Content, AMOUNT>>>::Output

Performs the + operation. Read more
Source§

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

Source§

type Output = Resource<Content>

The resulting type after applying the + operator.
Source§

fn add( self, rhs: Resource<Content>, ) -> <Bundle<Content, AMOUNT> as Add<Resource<Content>>>::Output

Performs the + operation. Read more
Source§

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

Source§

type Output = Resource<Content>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

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

Performs the += operation. Read more
Source§

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

Source§

fn add_assign(&mut self, rhs: Resource<Content>)

Performs the += operation. Read more
Source§

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

Source§

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

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

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

Source§

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

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

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn cmp(&self, other: &Resource<Content>) -> 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<Content> PartialEq<u32> for Resource<Content>
where Content: ResourceType,

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

Source§

fn eq(&self, other: &Resource<Content>) -> 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<Content> PartialOrd<u32> for Resource<Content>
where Content: ResourceType,

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

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 · 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<Content> Sum for Resource<Content>
where Content: ResourceType,

Source§

fn sum<I>(iter: I) -> Resource<Content>
where I: Iterator<Item = Resource<Content>>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<Content> Eq for Resource<Content>
where Content: Eq + ResourceType,

Source§

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

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§

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.