pub struct SignedAmount(_);
Expand description

SignedAmount

The SignedAmount type can be used to express Bitcoin amounts that supports arithmetic and conversion to various denominations.

Warning!

This type implements several arithmetic operations from core::ops. To prevent errors due to overflow or underflow when using these operations, it is advised to instead use the checked arithmetic methods whose names start with checked_. The operations from core::ops that Amount implements will panic when overflow or underflow occurs.

Implementations

The zero amount.

Exactly one satoshi.

Exactly one bitcoin.

The maximum value allowed as an amount. Useful for sanity checking.

Create an SignedAmount with satoshi precision and the given number of satoshis.

👎Deprecated since 0.29.0: use to_sat instead

Get the number of satoshis in this SignedAmount.

Gets the number of satoshis in this SignedAmount.

The maximum value of an SignedAmount.

The minimum value of an SignedAmount.

Convert from a value expressing bitcoins to an SignedAmount.

Parse a decimal string as a value in the given denomination.

Note: This only parses the value string. If you want to parse a value with denomination, use FromStr.

Parses amounts with denomination suffix like they are produced with Self::to_string_with_denomination or with fmt::Display. If you want to parse only the amount without the denomination, use Self::from_str_in.

Express this SignedAmount as a floating-point value in the given denomination.

Please be aware of the risk of using floating-point numbers.

👎Deprecated since 0.29.0: use to_btc instead

Express this SignedAmount as a floating-point value in Bitcoin.

Equivalent to to_float_in(Denomination::Bitcoin).

Please be aware of the risk of using floating-point numbers.

Express this SignedAmount as a floating-point value in Bitcoin.

Equivalent to to_float_in(Denomination::Bitcoin).

Please be aware of the risk of using floating-point numbers.

Convert this SignedAmount in floating-point notation with a given denomination. Can return error if the amount is too big, too precise or negative.

Please be aware of the risk of using floating-point numbers.

Create an object that implements fmt::Display using specified denomination.

Create an object that implements fmt::Display dynamically selecting denomination.

This will use BTC for values greater than or equal to 1 BTC and satoshis otherwise. To avoid confusion the denomination is always shown.

Format the value of this SignedAmount in the given denomination.

Does not include the denomination.

Get a string number of this SignedAmount in the given denomination.

Does not include the denomination.

Get a formatted string of this SignedAmount in the given denomination, suffixed with the abbreviation for the denomination.

Get the absolute value of this SignedAmount.

Returns a number representing sign of this SignedAmount.

  • 0 if the amount is zero
  • 1 if the amount is positive
  • -1 if the amount is negative

Returns true if this SignedAmount is positive and false if this SignedAmount is zero or negative.

Returns true if this SignedAmount is negative and false if this SignedAmount is zero or positive.

Get the absolute value of this SignedAmount. Returns None if overflow occurred. (self == min_value())

Checked addition. Returns None if overflow occurred.

Checked subtraction. Returns None if overflow occurred.

Checked multiplication. Returns None if overflow occurred.

Checked integer division. Be aware that integer division loses the remainder if no exact division can be made. Returns None if overflow occurred.

Checked remainder. Returns None if overflow occurred.

Subtraction that doesn’t allow negative SignedAmounts. Returns None if either self, rhs or the result is strictly negative.

Convert to an unsigned amount.

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
Performs the %= operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Calculate the sum over the iterator using checked arithmetic. If an over or underflow would happen it returns None. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.