pub struct Purchase { /* private fields */ }Expand description
A one-time cost: buying quantity units at unit_price each, optionally on a given date.
A Resource can have several over its life (an initial buy, later resupply at a new
price).
Built with Purchase::builder
§Example
use planter_core::{resources::Purchase, money::{Money, Currency}};
let purchase = Purchase::builder()
.quantity(5)
.unit_price(Money::from_minor_units(150, Currency::EUR))
.build();
assert_eq!(purchase.total(), Money::from_minor_units(750, Currency::EUR));Implementations§
Source§impl Purchase
impl Purchase
Sourcepub fn builder() -> PurchaseBuilder
pub fn builder() -> PurchaseBuilder
Create an instance of Purchase using the builder syntax
Source§impl Purchase
impl Purchase
Sourcepub const fn unit_price(&self) -> Money
pub const fn unit_price(&self) -> Money
Returns the price of one unit.
Sourcepub const fn date(&self) -> Option<DateTime<Utc>>
pub const fn date(&self) -> Option<DateTime<Utc>>
Returns when this purchase happens/happened, if known.
Sourcepub const fn total(&self) -> Money
pub const fn total(&self) -> Money
Returns the total cost of this purchase (quantity * unit_price, saturating).
Sourcepub const fn set_quantity(&mut self, quantity: u32)
pub const fn set_quantity(&mut self, quantity: u32)
Sets how many units this purchase bought.
Sourcepub const fn set_unit_price(&mut self, unit_price: Money)
pub const fn set_unit_price(&mut self, unit_price: Money)
Sets the price of one unit.
Sourcepub const fn set_date(&mut self, date: DateTime<Utc>)
pub const fn set_date(&mut self, date: DateTime<Utc>)
Sets when this purchase happens/happened.
Sourcepub const fn clear_date(&mut self)
pub const fn clear_date(&mut self)
Clears this purchase’s date.
Trait Implementations§
impl Eq for Purchase
impl StructuralPartialEq for Purchase
Auto Trait Implementations§
impl Freeze for Purchase
impl RefUnwindSafe for Purchase
impl Send for Purchase
impl Sync for Purchase
impl Unpin for Purchase
impl UnsafeUnpin for Purchase
impl UnwindSafe for Purchase
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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