Struct bitcoin::util::amount::Amount[][src]

pub struct Amount(_);
Expand description

Amount

The Amount 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. Also note that since the internal representation of amounts is unsigned, subtracting below zero is considered an underflow and will cause a panic if you’re not using the checked arithmetic methods.

Implementations

The zero amount.

Exactly one satoshi.

Exactly one bitcoin.

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

Get the number of satoshis in this Amount.

The maximum value of an Amount.

The minimum value of an Amount.

Convert from a value expressing bitcoins to an Amount.

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 Amount as a floating-point value in the given denomination.

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

Express this Amount 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 Amount 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.

Format the value of this Amount in the given denomination.

Does not include the denomination.

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

Does not include the denomination.

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

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.

Convert to a signed 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 !=.

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

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.