Struct levana_perpswap_cosmos::number::Signed
source · pub struct Signed<T> { /* private fields */ }
Expand description
Wrap up any UnsignedDecimal to provide negative values too.
Implementations§
source§impl Signed<Decimal256>
impl Signed<Decimal256>
sourcepub fn from_ratio_u256<A: Into<Uint256>, B: Into<Uint256>>(
numerator: A,
denominator: B,
) -> Self
pub fn from_ratio_u256<A: Into<Uint256>, B: Into<Uint256>>( numerator: A, denominator: B, ) -> Self
Returns the ratio (nominator / denominator) as a positive Number
sourcepub fn to_u128_with_precision(&self, precision: u32) -> Option<u128>
pub fn to_u128_with_precision(&self, precision: u32) -> Option<u128>
Represent as a u128 encoded with given decimal places
NOTE decimals may be dropped if precision isn’t sufficient to represent all digits completely
sourcepub fn from_fixed_u128(amount: u128, places: u32) -> Self
pub fn from_fixed_u128(amount: u128, places: u32) -> Self
helper to get from native currency to Number e.g. from uusd to UST, as a Decimal
sourcepub fn to_unsigned_key_bytes(&self) -> Option<[u8; 32]>
pub fn to_unsigned_key_bytes(&self) -> Option<[u8; 32]>
Useful for when Number is used as a PrimaryKey and is guaranteed to always be positive
sourcepub fn from_unsigned_key_bytes(bytes: [u8; 32]) -> Self
pub fn from_unsigned_key_bytes(bytes: [u8; 32]) -> Self
Round-tripping with Self::to_unsigned_key_bytes
source§impl<T: UnsignedDecimal> Signed<T>
impl<T: UnsignedDecimal> Signed<T>
sourcepub fn checked_add(self, rhs: Self) -> Result<Self>
pub fn checked_add(self, rhs: Self) -> Result<Self>
Addition that checks for integer overflow.
sourcepub fn checked_sub(self, rhs: Self) -> Result<Self>
pub fn checked_sub(self, rhs: Self) -> Result<Self>
Subtraction that checks for underflow
source§impl Signed<Decimal256>
impl Signed<Decimal256>
sourcepub fn checked_mul(self, rhs: Self) -> Result<Self>
pub fn checked_mul(self, rhs: Self) -> Result<Self>
Multiplication that checks for integer overflow
sourcepub fn checked_div(self, rhs: Self) -> Result<Self>
pub fn checked_div(self, rhs: Self) -> Result<Self>
Division that checks for underflow and divide-by-zero.
sourcepub fn approx_eq(self, other: Number) -> Result<bool>
pub fn approx_eq(self, other: Number) -> Result<bool>
equality check with allowance for precision diff
sourcepub fn approx_eq_eps(self, other: Number, eps: Number) -> Result<bool>
pub fn approx_eq_eps(self, other: Number, eps: Number) -> Result<bool>
equality check with allowance for precision diff
sourcepub fn approx_lt_relaxed(self, other: Number) -> Result<bool>
pub fn approx_lt_relaxed(self, other: Number) -> Result<bool>
less-than with allowance for precision diff
sourcepub fn approx_gt_relaxed(self, other: Number) -> Result<bool>
pub fn approx_gt_relaxed(self, other: Number) -> Result<bool>
greater-than with allowance for precision diff
sourcepub fn approx_gt_strict(self, other: Number) -> Result<bool>
pub fn approx_gt_strict(self, other: Number) -> Result<bool>
greater-than with restriction for precision diff
source§impl<T: UnsignedDecimal> Signed<T>
impl<T: UnsignedDecimal> Signed<T>
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Strictly less than 0, returns false on 0
sourcepub fn into_number(self) -> Signed<Decimal256>
pub fn into_number(self) -> Signed<Decimal256>
Convert into a general purpose Number.
sourcepub fn from_number(src: Signed<Decimal256>) -> Self
pub fn from_number(src: Signed<Decimal256>) -> Self
convert from a general purpose Number.
sourcepub fn try_into_non_negative_value(self) -> Option<T>
pub fn try_into_non_negative_value(self) -> Option<T>
If the value is positive or zero, return the inner T
. Otherwise return None
.
sourcepub fn try_into_non_zero(self) -> Option<NonZero<T>>
pub fn try_into_non_zero(self) -> Option<NonZero<T>>
Try to convert into a non-zero value
source§impl Signed<Decimal256>
impl Signed<Decimal256>
source§impl<T: UnsignedDecimal> Signed<T>
impl<T: UnsignedDecimal> Signed<T>
sourcepub fn checked_mul_number(self, rhs: Signed<Decimal256>) -> Result<Self>
pub fn checked_mul_number(self, rhs: Signed<Decimal256>) -> Result<Self>
Multiply by a raw number
source§impl<T: UnsignedDecimal> Signed<T>
impl<T: UnsignedDecimal> Signed<T>
sourcepub fn abs_unsigned(self) -> T
pub fn abs_unsigned(self) -> T
Absolute value, but return the T
underlying type directly
sourcepub fn is_strictly_positive(&self) -> bool
pub fn is_strictly_positive(&self) -> bool
Checks if this number is greater than 0.
sourcepub fn is_positive_or_zero(&self) -> bool
pub fn is_positive_or_zero(&self) -> bool
Checks if this number is greater than or equal to 0.
sourcepub fn map<U: UnsignedDecimal, F: FnOnce(T) -> U>(self, f: F) -> Signed<U>
pub fn map<U: UnsignedDecimal, F: FnOnce(T) -> U>(self, f: F) -> Signed<U>
Apply a function to the inner value and rewrap.
This will keep the current sign (positive or negative) in place, respecting invariants that a value of 0 must have negative set to false.
source§impl Signed<Decimal256>
impl Signed<Decimal256>
sourcepub fn to_pyth_price(
&self,
conf: u64,
publish_time: UnixTimestamp,
) -> Result<Price>
pub fn to_pyth_price( &self, conf: u64, publish_time: UnixTimestamp, ) -> Result<Price>
Converts a Number into a pyth price the exponent will always be 0 or negative
Trait Implementations§
source§impl<T: UnsignedDecimal> Add for Signed<T>
impl<T: UnsignedDecimal> Add for Signed<T>
source§impl<T: UnsignedDecimal> Debug for Signed<T>
impl<T: UnsignedDecimal> Debug for Signed<T>
source§impl<T: UnsignedDecimal> Default for Signed<T>
impl<T: UnsignedDecimal> Default for Signed<T>
source§impl<'de, T: UnsignedDecimal> Deserialize<'de> for Signed<T>
impl<'de, T: UnsignedDecimal> Deserialize<'de> for Signed<T>
Deserializes as string for serde
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 Signed<T>
impl<T: UnsignedDecimal> Display for Signed<T>
source§impl From<Signed<Decimal256>> for SignedLeverageToNotional
impl From<Signed<Decimal256>> for SignedLeverageToNotional
source§fn from(value: Signed<Decimal256>) -> Self
fn from(value: Signed<Decimal256>) -> Self
source§impl<T: UnsignedDecimal> FromStr for Signed<T>
impl<T: UnsignedDecimal> FromStr for Signed<T>
source§impl<T: UnsignedDecimal> JsonSchema for Signed<T>
impl<T: UnsignedDecimal> JsonSchema for Signed<T>
source§fn schema_name() -> String
fn schema_name() -> String
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§fn json_schema(_: &mut SchemaGenerator) -> Schema
fn json_schema(_: &mut SchemaGenerator) -> Schema
source§impl<T: UnsignedDecimal> Neg for Signed<T>
impl<T: UnsignedDecimal> Neg for Signed<T>
source§impl<T: UnsignedDecimal> Ord for Signed<T>
impl<T: UnsignedDecimal> Ord for Signed<T>
source§impl<T: PartialEq> PartialEq for Signed<T>
impl<T: PartialEq> PartialEq for Signed<T>
source§impl<T: UnsignedDecimal> PartialOrd for Signed<T>
impl<T: UnsignedDecimal> PartialOrd for Signed<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 Signed<T>
impl<T: UnsignedDecimal> Serialize for Signed<T>
Serializes as a string for serde
source§impl<T: UnsignedDecimal> Sub for Signed<T>
impl<T: UnsignedDecimal> Sub for Signed<T>
impl<T: Copy> Copy for Signed<T>
impl<T: Eq> Eq for Signed<T>
impl<T> StructuralPartialEq for Signed<T>
Auto Trait Implementations§
impl<T> Freeze for Signed<T>where
T: Freeze,
impl<T> RefUnwindSafe for Signed<T>where
T: RefUnwindSafe,
impl<T> Send for Signed<T>where
T: Send,
impl<T> Sync for Signed<T>where
T: Sync,
impl<T> Unpin for Signed<T>where
T: Unpin,
impl<T> UnwindSafe for Signed<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