Struct levana_perpswap_cosmos::number::NonZero
source · pub struct NonZero<T>(/* private fields */);
Expand description
Ensure that the inner value is never 0.
Implementations§
source§impl<T: UnsignedDecimal> NonZero<T>
impl<T: UnsignedDecimal> NonZero<T>
source§impl<T: UnsignedDecimal> NonZero<T>
impl<T: UnsignedDecimal> NonZero<T>
sourcepub fn to_be_bytes(&self) -> [u8; 32]
pub fn to_be_bytes(&self) -> [u8; 32]
Convert into a big-endian array.
sourcepub fn from_be_bytes(bytes: [u8; 32]) -> Option<Self>
pub fn from_be_bytes(bytes: [u8; 32]) -> Option<Self>
Convert raw bytes into this value.
Intended for use with cw-storage-plus.
sourcepub fn into_signed(self) -> Signed<T>
pub fn into_signed(self) -> Signed<T>
Turn into a signed value.
sourcepub fn into_decimal256(self) -> Decimal256
pub fn into_decimal256(self) -> Decimal256
Convert into a general purpose Decimal256.
sourcepub fn into_number_gt_zero(self) -> NumberGtZero
pub fn into_number_gt_zero(self) -> NumberGtZero
Convert into NonZero<Decimal>
sourcepub fn into_number(self) -> Signed<Decimal256>
pub fn into_number(self) -> Signed<Decimal256>
Convert into a general purpose Number.
sourcepub fn try_from_number(src: Signed<Decimal256>) -> Option<Self>
pub fn try_from_number(src: Signed<Decimal256>) -> Option<Self>
Try to convert a general purpose Number into this type.
sourcepub fn try_from_decimal(src: Decimal256) -> Option<Self>
pub fn try_from_decimal(src: Decimal256) -> Option<Self>
Try to convert a general purpose Decimal256 into this type.
sourcepub fn try_from_signed(src: Signed<T>) -> Result<Self>
pub fn try_from_signed(src: Signed<T>) -> Result<Self>
Try to convert a signed value into a non-zero.
sourcepub fn checked_add(self, rhs: T) -> Result<Self>
pub fn checked_add(self, rhs: T) -> Result<Self>
Add an unsigned value to this non-zero
This can fail due to overflow error, but is guaranteed to not give a value of 0.
sourcepub fn checked_sub(self, rhs: T) -> Result<Self>
pub fn checked_sub(self, rhs: T) -> Result<Self>
Subtract an unsigned value.
This can fail if the result would be either negative or zero.
sourcepub fn checked_add_signed(self, rhs: Signed<T>) -> Result<Self>
pub fn checked_add_signed(self, rhs: Signed<T>) -> Result<Self>
Try to add a signed value to this, erroring if it results in a negative or zero result.
sourcepub fn checked_sub_signed(self, rhs: Signed<T>) -> Result<Self>
pub fn checked_sub_signed(self, rhs: Signed<T>) -> Result<Self>
Try to subtract a signed value from this, erroring if it results in a negative or zero result.
source§impl NonZero<Collateral>
impl NonZero<Collateral>
sourcepub fn checked_mul_non_zero(
self,
rhs: NonZero<Decimal256>,
) -> Result<NonZero<Collateral>>
pub fn checked_mul_non_zero( self, rhs: NonZero<Decimal256>, ) -> Result<NonZero<Collateral>>
Multiply by the given non-zero decimal.
sourcepub fn checked_div_collateral(
self,
rhs: NonZero<Collateral>,
) -> Result<NonZero<Decimal256>>
pub fn checked_div_collateral( self, rhs: NonZero<Collateral>, ) -> Result<NonZero<Decimal256>>
Divide two non-zero collateral values to get the ratio between them.
This can be used for cases like calculating the max gains.
Trait Implementations§
source§impl<'de, T: UnsignedDecimal> Deserialize<'de> for NonZero<T>
impl<'de, T: UnsignedDecimal> Deserialize<'de> for NonZero<T>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<T: UnsignedDecimal> Display for NonZero<T>
impl<T: UnsignedDecimal> Display for NonZero<T>
source§impl From<NonZero<Decimal256>> for LeverageToBase
impl From<NonZero<Decimal256>> for LeverageToBase
source§fn from(value: NonZero<Decimal256>) -> Self
fn from(value: NonZero<Decimal256>) -> Self
source§impl<T: UnsignedDecimal> FromStr for NonZero<T>
impl<T: UnsignedDecimal> FromStr for NonZero<T>
source§impl<T: UnsignedDecimal> JsonSchema for NonZero<T>
impl<T: UnsignedDecimal> JsonSchema for NonZero<T>
source§fn schema_name() -> String
fn schema_name() -> String
source§fn json_schema(_: &mut SchemaGenerator) -> Schema
fn json_schema(_: &mut SchemaGenerator) -> Schema
§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl<T: Ord> Ord for NonZero<T>
impl<T: Ord> Ord for NonZero<T>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<T: PartialEq> PartialEq for NonZero<T>
impl<T: PartialEq> PartialEq for NonZero<T>
source§impl<T: PartialOrd> PartialOrd for NonZero<T>
impl<T: PartialOrd> PartialOrd for NonZero<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<T: UnsignedDecimal> Serialize for NonZero<T>
impl<T: UnsignedDecimal> Serialize for NonZero<T>
impl<T: Copy> Copy for NonZero<T>
impl<T: Eq> Eq for NonZero<T>
impl<T> StructuralPartialEq for NonZero<T>
Auto Trait Implementations§
impl<T> Freeze for NonZero<T>where
T: Freeze,
impl<T> RefUnwindSafe for NonZero<T>where
T: RefUnwindSafe,
impl<T> Send for NonZero<T>where
T: Send,
impl<T> Sync for NonZero<T>where
T: Sync,
impl<T> Unpin for NonZero<T>where
T: Unpin,
impl<T> UnwindSafe for NonZero<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moresource§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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
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