Amount

Struct Amount 

Source
pub struct Amount<'ctx> { /* private fields */ }
Expand description

Amount with multiple commodities, or simple zero.

Implementations§

Source§

impl<'ctx> Amount<'ctx>

Source

pub fn zero() -> Self

Creates an Amount with zero value.

Source

pub fn from_value(amount: Decimal, commodity: Commodity<'ctx>) -> Self

Creates an Amount with single value and commodity.

Source

pub fn from_values<T>(values: T) -> Self
where T: IntoIterator<Item = (Decimal, Commodity<'ctx>)>,

Creates an Amount from a set of values.

Source

pub fn into_values(self) -> HashMap<Commodity<'ctx>, Decimal>

Takes out the instance and returns map from commodity to its value.

Source

pub fn iter(&self) -> impl Iterator<Item = SingleAmount<'ctx>> + '_

Returns iterator over its amount.

Source

pub fn as_inline_display(&self) -> impl Display + '_

Returns an objectt to print the amount as inline.

Source

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.

Source

pub fn is_zero(&self) -> bool

Returns true if this is zero, including zero commodities.

Source

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.

Source

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.

Source

pub fn round(self, ctx: &ReportContext<'_>) -> Self

Rounds the given Amount and returns the new instance.

Source

pub fn round_mut(&mut self, ctx: &ReportContext<'_>)

Rounds the Amount in-place with the given context provided precision.

Source

pub fn negate(self) -> Self

Creates negated instance.

Source

pub fn check_div(self, rhs: Decimal) -> Result<Self, EvalError>

Run division with error checking.

Trait Implementations§

Source§

impl<'ctx> Add<SingleAmount<'ctx>> for Amount<'ctx>

Source§

type Output = Amount<'ctx>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: SingleAmount<'ctx>) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Amount<'_>

Source§

type Output = Amount<'_>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<'ctx> AddAssign<SingleAmount<'ctx>> for Amount<'ctx>

Source§

fn add_assign(&mut self, rhs: SingleAmount<'ctx>)

Performs the += operation. Read more
Source§

impl AddAssign for Amount<'_>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<'ctx> Clone for Amount<'ctx>

Source§

fn clone(&self) -> Amount<'ctx>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'ctx> Debug for Amount<'ctx>

Source§

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

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

impl<'ctx> Default for Amount<'ctx>

Source§

fn default() -> Amount<'ctx>

Returns the “default value” for a type. Read more
Source§

impl<'ctx> From<SingleAmount<'ctx>> for Amount<'ctx>

Source§

fn from(value: SingleAmount<'ctx>) -> Self

Converts to this type from the input type.
Source§

impl Mul<Decimal> for Amount<'_>

Source§

type Output = Amount<'_>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Decimal) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<Decimal> for Amount<'_>

Source§

fn mul_assign(&mut self, rhs: Decimal)

Performs the *= operation. Read more
Source§

impl Neg for Amount<'_>

Source§

type Output = Amount<'_>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<'ctx> PartialEq for Amount<'ctx>

Source§

fn eq(&self, other: &Amount<'ctx>) -> 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 Sub for Amount<'_>

Source§

type Output = Amount<'_>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Amount<'_>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<'ctx> TryFrom<&Amount<'ctx>> for SingleAmount<'ctx>

Source§

type Error = EvalError

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

fn try_from(value: &Amount<'ctx>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'ctx> TryFrom<Amount<'ctx>> for SingleAmount<'ctx>

Source§

type Error = EvalError

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

fn try_from(value: Amount<'ctx>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'ctx> Eq for Amount<'ctx>

Source§

impl<'ctx> StructuralPartialEq for Amount<'ctx>

Auto Trait Implementations§

§

impl<'ctx> Freeze for Amount<'ctx>

§

impl<'ctx> RefUnwindSafe for Amount<'ctx>

§

impl<'ctx> Send for Amount<'ctx>

§

impl<'ctx> Sync for Amount<'ctx>

§

impl<'ctx> Unpin for Amount<'ctx>

§

impl<'ctx> UnwindSafe for Amount<'ctx>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.