pub struct ZatBalance(/* private fields */);
Expand description
A type-safe representation of a Zcash value delta, in zatoshis.
An ZatBalance can only be constructed from an integer that is within the valid monetary
range of {-MAX_MONEY..MAX_MONEY}
(where MAX_MONEY
= 21,000,000 × 10⁸ zatoshis),
and this is preserved as an invariant internally. (A Transaction
containing serialized
invalid ZatBalances would also be rejected by the network consensus rules.)
Implementations§
Source§impl ZatBalance
impl ZatBalance
Sourcepub const fn const_from_i64(amount: i64) -> Self
pub const fn const_from_i64(amount: i64) -> Self
Creates a constant ZatBalance from an i64.
Panics: if the amount is outside the range {-MAX_BALANCE..MAX_BALANCE}
.
Sourcepub const fn const_from_u64(amount: u64) -> Self
pub const fn const_from_u64(amount: u64) -> Self
Creates a constant ZatBalance from a u64.
Panics: if the amount is outside the range {0..MAX_BALANCE}
.
Sourcepub fn from_i64(amount: i64) -> Result<Self, BalanceError>
pub fn from_i64(amount: i64) -> Result<Self, BalanceError>
Creates an ZatBalance from an i64.
Returns an error if the amount is outside the range {-MAX_BALANCE..MAX_BALANCE}
.
Sourcepub fn from_nonnegative_i64(amount: i64) -> Result<Self, BalanceError>
pub fn from_nonnegative_i64(amount: i64) -> Result<Self, BalanceError>
Creates a non-negative ZatBalance from an i64.
Returns an error if the amount is outside the range {0..MAX_BALANCE}
.
Sourcepub fn from_u64(amount: u64) -> Result<Self, BalanceError>
pub fn from_u64(amount: u64) -> Result<Self, BalanceError>
Creates an ZatBalance from a u64.
Returns an error if the amount is outside the range {0..MAX_MONEY}
.
Sourcepub fn from_i64_le_bytes(bytes: [u8; 8]) -> Result<Self, BalanceError>
pub fn from_i64_le_bytes(bytes: [u8; 8]) -> Result<Self, BalanceError>
Reads an ZatBalance from a signed 64-bit little-endian integer.
Returns an error if the amount is outside the range {-MAX_BALANCE..MAX_BALANCE}
.
Sourcepub fn from_nonnegative_i64_le_bytes(
bytes: [u8; 8],
) -> Result<Self, BalanceError>
pub fn from_nonnegative_i64_le_bytes( bytes: [u8; 8], ) -> Result<Self, BalanceError>
Reads a non-negative ZatBalance from a signed 64-bit little-endian integer.
Returns an error if the amount is outside the range {0..MAX_BALANCE}
.
Sourcepub fn from_u64_le_bytes(bytes: [u8; 8]) -> Result<Self, BalanceError>
pub fn from_u64_le_bytes(bytes: [u8; 8]) -> Result<Self, BalanceError>
Reads an ZatBalance from an unsigned 64-bit little-endian integer.
Returns an error if the amount is outside the range {0..MAX_BALANCE}
.
Sourcepub fn to_i64_le_bytes(self) -> [u8; 8]
pub fn to_i64_le_bytes(self) -> [u8; 8]
Returns the ZatBalance encoded as a signed 64-bit little-endian integer.
Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true
if self
is positive and false
if the ZatBalance is zero or
negative.
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true
if self
is negative and false
if the ZatBalance is zero or
positive.
pub fn sum<I: IntoIterator<Item = ZatBalance>>(values: I) -> Option<ZatBalance>
Trait Implementations§
Source§impl Add<ZatBalance> for Option<ZatBalance>
impl Add<ZatBalance> for Option<ZatBalance>
Source§type Output = Option<ZatBalance>
type Output = Option<ZatBalance>
+
operator.Source§fn add(self, rhs: ZatBalance) -> Option<ZatBalance>
fn add(self, rhs: ZatBalance) -> Option<ZatBalance>
+
operation. Read moreSource§impl Add for ZatBalance
impl Add for ZatBalance
Source§type Output = Option<ZatBalance>
type Output = Option<ZatBalance>
+
operator.Source§fn add(self, rhs: ZatBalance) -> Option<ZatBalance>
fn add(self, rhs: ZatBalance) -> Option<ZatBalance>
+
operation. Read moreSource§impl Clone for ZatBalance
impl Clone for ZatBalance
Source§fn clone(&self) -> ZatBalance
fn clone(&self) -> ZatBalance
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ZatBalance
impl Debug for ZatBalance
Source§impl DynamicUsage for ZatBalance
impl DynamicUsage for ZatBalance
Source§impl From<&ZatBalance> for i64
impl From<&ZatBalance> for i64
Source§fn from(amount: &ZatBalance) -> i64
fn from(amount: &ZatBalance) -> i64
Source§impl From<&Zatoshis> for ZatBalance
impl From<&Zatoshis> for ZatBalance
Source§impl From<ZatBalance> for i64
impl From<ZatBalance> for i64
Source§fn from(amount: ZatBalance) -> i64
fn from(amount: ZatBalance) -> i64
Source§impl From<Zatoshis> for ZatBalance
impl From<Zatoshis> for ZatBalance
Source§impl Mul<usize> for ZatBalance
impl Mul<usize> for ZatBalance
Source§impl Neg for ZatBalance
impl Neg for ZatBalance
Source§impl Ord for ZatBalance
impl Ord for ZatBalance
Source§fn cmp(&self, other: &ZatBalance) -> Ordering
fn cmp(&self, other: &ZatBalance) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ZatBalance
impl PartialEq for ZatBalance
Source§impl PartialOrd for ZatBalance
impl PartialOrd for ZatBalance
Source§impl Sub<ZatBalance> for Option<ZatBalance>
impl Sub<ZatBalance> for Option<ZatBalance>
Source§type Output = Option<ZatBalance>
type Output = Option<ZatBalance>
-
operator.Source§fn sub(self, rhs: ZatBalance) -> Option<ZatBalance>
fn sub(self, rhs: ZatBalance) -> Option<ZatBalance>
-
operation. Read moreSource§impl Sub for ZatBalance
impl Sub for ZatBalance
Source§type Output = Option<ZatBalance>
type Output = Option<ZatBalance>
-
operator.Source§fn sub(self, rhs: ZatBalance) -> Option<ZatBalance>
fn sub(self, rhs: ZatBalance) -> Option<ZatBalance>
-
operation. Read moreSource§impl<'a> Sum<&'a ZatBalance> for Option<ZatBalance>
impl<'a> Sum<&'a ZatBalance> for Option<ZatBalance>
Source§fn sum<I: Iterator<Item = &'a ZatBalance>>(iter: I) -> Self
fn sum<I: Iterator<Item = &'a ZatBalance>>(iter: I) -> Self
Self
from the elements by “summing up”
the items.Source§impl Sum<ZatBalance> for Option<ZatBalance>
impl Sum<ZatBalance> for Option<ZatBalance>
Source§fn sum<I: Iterator<Item = ZatBalance>>(iter: I) -> Self
fn sum<I: Iterator<Item = ZatBalance>>(iter: I) -> Self
Self
from the elements by “summing up”
the items.Source§impl TryFrom<ZatBalance> for Zatoshis
impl TryFrom<ZatBalance> for Zatoshis
Source§type Error = BalanceError
type Error = BalanceError
Source§impl TryFrom<ZatBalance> for u64
impl TryFrom<ZatBalance> for u64
Source§type Error = BalanceError
type Error = BalanceError
Source§impl TryFrom<i64> for ZatBalance
impl TryFrom<i64> for ZatBalance
Source§type Error = BalanceError
type Error = BalanceError
impl Copy for ZatBalance
impl Eq for ZatBalance
impl StructuralPartialEq for ZatBalance
Auto Trait Implementations§
impl Freeze for ZatBalance
impl RefUnwindSafe for ZatBalance
impl Send for ZatBalance
impl Sync for ZatBalance
impl Unpin for ZatBalance
impl UnwindSafe for ZatBalance
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> 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