pub struct AssetAmount { /* private fields */ }Expand description
A validated fungible asset amount.
Values created through this type’s constructors, conversions, and arithmetic operations wrap
a Felt whose canonical value is at most AssetAmount::MAX_U64. The API mirrors
miden_protocol::asset::AssetAmount so that on-chain and off-chain code handle amounts the
same way, while the felt representation avoids integer/felt conversions around the
transaction kernel procedures.
Unlike a raw Felt, an amount only offers integer semantics: addition and subtraction
panic on overflow and underflow instead of wrapping, and comparison follows the canonical
integer value. Finite field arithmetic (wrapping at the field modulus, division via the
multiplicative inverse) is intentionally unavailable; convert with AssetAmount::as_u64
when full integer functionality is needed.
Implementations§
Source§impl AssetAmount
impl AssetAmount
Sourcepub const MAX_U64: u64
pub const MAX_U64: u64
The maximum value an asset amount can represent, equal to 2^63 - 2^31.
Matches miden_protocol::asset::AssetAmount::MAX, which is chosen so that an amount fits
in a field element as both a positive and a negative value.
Sourcepub fn max() -> Self
pub fn max() -> Self
Returns the maximum representable asset amount, equal to Self::MAX_U64.
Sourcepub fn new(amount: u64) -> Result<Self, AssetAmountError>
pub fn new(amount: u64) -> Result<Self, AssetAmountError>
Returns a new asset amount if amount does not exceed Self::MAX_U64.
§Errors
Returns an error if amount is greater than Self::MAX_U64.
Trait Implementations§
Source§impl Add for AssetAmount
impl Add for AssetAmount
Source§fn add(self, other: Self) -> Self
fn add(self, other: Self) -> Self
Adds two asset amounts, staying in the field domain.
§Panics
Panics if either operand or the sum exceeds AssetAmount::MAX_U64.
Source§type Output = AssetAmount
type Output = AssetAmount
+ operator.Source§impl Clone for AssetAmount
impl Clone for AssetAmount
Source§fn clone(&self) -> AssetAmount
fn clone(&self) -> AssetAmount
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 AssetAmount
Source§impl Debug for AssetAmount
impl Debug for AssetAmount
Source§impl Default for AssetAmount
impl Default for AssetAmount
Source§impl Display for AssetAmount
impl Display for AssetAmount
impl Eq for AssetAmount
Source§impl From<AssetAmount> for u64
impl From<AssetAmount> for u64
Source§fn from(amount: AssetAmount) -> Self
fn from(amount: AssetAmount) -> Self
Source§impl From<AssetAmount> for Felt
impl From<AssetAmount> for Felt
Source§fn from(amount: AssetAmount) -> Self
fn from(amount: AssetAmount) -> Self
Source§impl From<u8> for AssetAmount
impl From<u8> for AssetAmount
Source§impl From<u16> for AssetAmount
impl From<u16> for AssetAmount
Source§impl From<u32> for AssetAmount
impl From<u32> for AssetAmount
Source§impl Hash for AssetAmount
impl Hash for AssetAmount
Source§impl Ord for AssetAmount
impl Ord for AssetAmount
Source§fn cmp(&self, other: &AssetAmount) -> Ordering
fn cmp(&self, other: &AssetAmount) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for AssetAmount
impl PartialEq for AssetAmount
Source§impl PartialOrd for AssetAmount
impl PartialOrd for AssetAmount
impl StructuralPartialEq for AssetAmount
Source§impl Sub for AssetAmount
impl Sub for AssetAmount
Source§fn sub(self, other: Self) -> Self
fn sub(self, other: Self) -> Self
Subtracts other from self, staying in the field domain.
§Panics
Panics if either operand exceeds AssetAmount::MAX_U64 or if other is greater than
self.
Source§type Output = AssetAmount
type Output = AssetAmount
- operator.Source§impl TryFrom<Felt> for AssetAmount
impl TryFrom<Felt> for AssetAmount
Auto Trait Implementations§
impl Freeze for AssetAmount
impl RefUnwindSafe for AssetAmount
impl Send for AssetAmount
impl Sync for AssetAmount
impl Unpin for AssetAmount
impl UnsafeUnpin for AssetAmount
impl UnwindSafe for AssetAmount
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<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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more