pub struct MoneyAmount(pub Decimal);Expand description
A parsed monetary amount with decimal precision.
This type represents a non-negative decimal value parsed from a human-readable string. It preserves the original precision, which is important when converting to token amounts with specific decimal places.
§Precision
The scale method returns the number of decimal places,
and mantissa returns the value as an integer.
For example, "10.50" has scale 2 and mantissa 1050.
Tuple Fields§
§0: DecimalImplementations§
Source§impl MoneyAmount
impl MoneyAmount
Source§impl MoneyAmount
impl MoneyAmount
Sourcepub fn parse(input: &str) -> Result<Self, MoneyAmountParseError>
pub fn parse(input: &str) -> Result<Self, MoneyAmountParseError>
Parses a human-readable currency string into a MoneyAmount.
Currency symbols, thousand separators, and whitespace are stripped before parsing. The result must be a non-negative number within the allowed range.
§Errors
Returns an error if:
- The string cannot be parsed as a number
- The value is negative
- The value is outside the allowed range
Source§impl MoneyAmount
impl MoneyAmount
Sourcepub fn to_token_amount<T: ScaleFromMantissa>(
self,
decimals: u8,
) -> Result<T, MoneyAmountParseError>
pub fn to_token_amount<T: ScaleFromMantissa>( self, decimals: u8, ) -> Result<T, MoneyAmountParseError>
Converts this amount to a token-specific integer scaled to the given decimal places.
This is the shared logic used by chain-specific token deployments (EVM, Solana) to convert human-readable amounts into on-chain token units.
§Errors
Returns an error if:
- The input precision exceeds the token’s decimal places
- The scaled value overflows the target type
T
Trait Implementations§
Source§impl Clone for MoneyAmount
impl Clone for MoneyAmount
Source§fn clone(&self) -> MoneyAmount
fn clone(&self) -> MoneyAmount
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for MoneyAmount
Source§impl Debug for MoneyAmount
impl Debug for MoneyAmount
Source§impl Display for MoneyAmount
impl Display for MoneyAmount
impl Eq for MoneyAmount
Source§impl From<u128> for MoneyAmount
impl From<u128> for MoneyAmount
Source§impl FromStr for MoneyAmount
impl FromStr for MoneyAmount
Source§impl PartialEq for MoneyAmount
impl PartialEq for MoneyAmount
impl StructuralPartialEq for MoneyAmount
Source§impl TryFrom<&str> for MoneyAmount
impl TryFrom<&str> for MoneyAmount
Auto Trait Implementations§
impl Freeze for MoneyAmount
impl RefUnwindSafe for MoneyAmount
impl Send for MoneyAmount
impl Sync for MoneyAmount
impl Unpin for MoneyAmount
impl UnsafeUnpin for MoneyAmount
impl UnwindSafe for MoneyAmount
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more