pub struct Currency {
pub gold: u64,
pub silver: u64,
pub copper: u64,
}Expand description
Three-tier currency: gold, silver, copper. 100 copper = 1 silver, 100 silver = 1 gold.
Fields§
§gold: u64§silver: u64§copper: u64Implementations§
Source§impl Currency
impl Currency
pub fn new(gold: u64, silver: u64, copper: u64) -> Self
Sourcepub fn from_copper(total: u64) -> Self
pub fn from_copper(total: u64) -> Self
Create currency from a total copper amount.
Sourcepub fn silver(amount: u64) -> Self
pub fn silver(amount: u64) -> Self
Create currency from a silver amount (normalizes automatically).
Sourcepub fn copper(amount: u64) -> Self
pub fn copper(amount: u64) -> Self
Create currency from a copper amount (normalizes automatically).
pub fn zero() -> Self
Sourcepub fn to_copper_total(&self) -> u64
pub fn to_copper_total(&self) -> u64
Total value expressed in copper.
Sourcepub fn has_at_least(&self, amount: &Currency) -> bool
pub fn has_at_least(&self, amount: &Currency) -> bool
Check if this wallet has at least amount.
Sourcepub fn try_subtract(&mut self, amount: &Currency) -> bool
pub fn try_subtract(&mut self, amount: &Currency) -> bool
Attempt to subtract amount from this currency.
Returns true on success (and modifies self), false if insufficient funds.
Sourcepub fn multiply(&self, factor: u32) -> Self
pub fn multiply(&self, factor: u32) -> Self
Multiply the currency by a scalar (e.g. for quantity pricing).
Sourcepub fn scale(&self, factor: f32) -> Self
pub fn scale(&self, factor: f32) -> Self
Scale by a floating-point factor (for discounts / surcharges).
pub fn is_zero(&self) -> bool
Trait Implementations§
impl Eq for Currency
Source§impl Ord for Currency
impl Ord for Currency
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Currency
impl PartialOrd for Currency
impl StructuralPartialEq for Currency
Auto Trait Implementations§
impl Freeze for Currency
impl RefUnwindSafe for Currency
impl Send for Currency
impl Sync for Currency
impl Unpin for Currency
impl UnsafeUnpin for Currency
impl UnwindSafe for Currency
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.