pub struct Amount<'ctx> { /* private fields */ }
Expand description
Amount with multiple commodities, or simple zero.
Implementations§
Source§impl<'ctx> Amount<'ctx>
impl<'ctx> Amount<'ctx>
Sourcepub fn from_value(amount: Decimal, commodity: Commodity<'ctx>) -> Self
pub fn from_value(amount: Decimal, commodity: Commodity<'ctx>) -> Self
Creates an Amount
with single value and commodity.
Sourcepub fn from_values<T>(values: T) -> Self
pub fn from_values<T>(values: T) -> Self
Creates an Amount
from a set of values.
Sourcepub fn into_values(self) -> HashMap<Commodity<'ctx>, Decimal>
pub fn into_values(self) -> HashMap<Commodity<'ctx>, Decimal>
Takes out the instance and returns map from commodity to its value.
Sourcepub fn iter(&self) -> impl Iterator<Item = SingleAmount<'ctx>> + '_
pub fn iter(&self) -> impl Iterator<Item = SingleAmount<'ctx>> + '_
Returns iterator over its amount.
Sourcepub fn as_inline_display(&self) -> impl Display + '_
pub fn as_inline_display(&self) -> impl Display + '_
Returns an objectt to print the amount as inline.
Sourcepub fn is_absolute_zero(&self) -> bool
pub fn is_absolute_zero(&self) -> bool
Returns true
if this is ‘non-commoditized zero’, which is used to assert
the account balance is completely zero.
Sourcepub fn remove_zero_entries(&mut self)
pub fn remove_zero_entries(&mut self)
Removes zero values, useful when callers doesn’t care zero value.
However, if caller must distinguish 0
and 0 commodity
,
caller must not use this method.
Sourcepub fn maybe_pair(&self) -> Option<(SingleAmount<'ctx>, SingleAmount<'ctx>)>
pub fn maybe_pair(&self) -> Option<(SingleAmount<'ctx>, SingleAmount<'ctx>)>
Returns pair of commodity amount, if the amount contains exactly 2 commodities. Otherwise returns None.
Sourcepub fn round(self, ctx: &ReportContext<'_>) -> Self
pub fn round(self, ctx: &ReportContext<'_>) -> Self
Rounds the given Amount and returns the new instance.
Sourcepub fn round_mut(&mut self, ctx: &ReportContext<'_>)
pub fn round_mut(&mut self, ctx: &ReportContext<'_>)
Rounds the Amount in-place with the given context provided precision.
Trait Implementations§
Source§impl<'ctx> Add<SingleAmount<'ctx>> for Amount<'ctx>
impl<'ctx> Add<SingleAmount<'ctx>> for Amount<'ctx>
Source§impl<'ctx> AddAssign<SingleAmount<'ctx>> for Amount<'ctx>
impl<'ctx> AddAssign<SingleAmount<'ctx>> for Amount<'ctx>
Source§fn add_assign(&mut self, rhs: SingleAmount<'ctx>)
fn add_assign(&mut self, rhs: SingleAmount<'ctx>)
+=
operation. Read moreSource§impl AddAssign for Amount<'_>
impl AddAssign for Amount<'_>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl<'ctx> From<SingleAmount<'ctx>> for Amount<'ctx>
impl<'ctx> From<SingleAmount<'ctx>> for Amount<'ctx>
Source§fn from(value: SingleAmount<'ctx>) -> Self
fn from(value: SingleAmount<'ctx>) -> Self
Source§impl MulAssign<Decimal> for Amount<'_>
impl MulAssign<Decimal> for Amount<'_>
Source§fn mul_assign(&mut self, rhs: Decimal)
fn mul_assign(&mut self, rhs: Decimal)
*=
operation. Read moreSource§impl SubAssign for Amount<'_>
impl SubAssign for Amount<'_>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more