Struct ZatBalance

Source
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

Source

pub const fn zero() -> Self

Returns a zero-valued ZatBalance.

Source

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}.

Source

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}.

Source

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}.

Source

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}.

Source

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}.

Source

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}.

Source

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}.

Source

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}.

Source

pub fn to_i64_le_bytes(self) -> [u8; 8]

Returns the ZatBalance encoded as a signed 64-bit little-endian integer.

Source

pub const fn is_positive(self) -> bool

Returns true if self is positive and false if the ZatBalance is zero or negative.

Source

pub const fn is_negative(self) -> bool

Returns true if self is negative and false if the ZatBalance is zero or positive.

Source

pub fn sum<I: IntoIterator<Item = ZatBalance>>(values: I) -> Option<ZatBalance>

Trait Implementations§

Source§

impl Add<ZatBalance> for Option<ZatBalance>

Source§

type Output = Option<ZatBalance>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: ZatBalance) -> Option<ZatBalance>

Performs the + operation. Read more
Source§

impl Add for ZatBalance

Source§

type Output = Option<ZatBalance>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: ZatBalance) -> Option<ZatBalance>

Performs the + operation. Read more
Source§

impl Clone for ZatBalance

Source§

fn clone(&self) -> ZatBalance

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ZatBalance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DynamicUsage for ZatBalance

Source§

fn dynamic_usage(&self) -> usize

Returns a best estimate of the amount of heap-allocated memory used by this type. Read more
Source§

fn dynamic_usage_bounds(&self) -> (usize, Option<usize>)

Returns the lower and upper bounds on the amount of heap-allocated memory used by this type. Read more
Source§

impl From<&ZatBalance> for i64

Source§

fn from(amount: &ZatBalance) -> i64

Converts to this type from the input type.
Source§

impl From<&Zatoshis> for ZatBalance

Source§

fn from(n: &Zatoshis) -> Self

Converts to this type from the input type.
Source§

impl From<ZatBalance> for i64

Source§

fn from(amount: ZatBalance) -> i64

Converts to this type from the input type.
Source§

impl From<Zatoshis> for ZatBalance

Source§

fn from(n: Zatoshis) -> Self

Converts to this type from the input type.
Source§

impl Mul<usize> for ZatBalance

Source§

type Output = Option<ZatBalance>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: usize) -> Option<ZatBalance>

Performs the * operation. Read more
Source§

impl Neg for ZatBalance

Source§

type Output = ZatBalance

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Ord for ZatBalance

Source§

fn cmp(&self, other: &ZatBalance) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ZatBalance

Source§

fn eq(&self, other: &ZatBalance) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for ZatBalance

Source§

fn partial_cmp(&self, other: &ZatBalance) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub<ZatBalance> for Option<ZatBalance>

Source§

type Output = Option<ZatBalance>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: ZatBalance) -> Option<ZatBalance>

Performs the - operation. Read more
Source§

impl Sub for ZatBalance

Source§

type Output = Option<ZatBalance>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: ZatBalance) -> Option<ZatBalance>

Performs the - operation. Read more
Source§

impl<'a> Sum<&'a ZatBalance> for Option<ZatBalance>

Source§

fn sum<I: Iterator<Item = &'a ZatBalance>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum<ZatBalance> for Option<ZatBalance>

Source§

fn sum<I: Iterator<Item = ZatBalance>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl TryFrom<ZatBalance> for Zatoshis

Source§

type Error = BalanceError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ZatBalance) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<ZatBalance> for u64

Source§

type Error = BalanceError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ZatBalance) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i64> for ZatBalance

Source§

type Error = BalanceError

The type returned in the event of a conversion error.
Source§

fn try_from(value: i64) -> Result<Self, BalanceError>

Performs the conversion.
Source§

impl Copy for ZatBalance

Source§

impl Eq for ZatBalance

Source§

impl StructuralPartialEq for ZatBalance

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V