Struct levana_perpswap_cosmos_msg::prelude::Signed
pub struct Signed<T> { /* private fields */ }
Expand description
Wrap up any UnsignedDecimal to provide negative values too.
Implementations§
§impl Signed<Decimal256>
impl Signed<Decimal256>
pub fn from_ratio_u256<A, B>(numerator: A, denominator: B) -> Signed<Decimal256>where
A: Into<Uint256>,
B: Into<Uint256>,
pub fn from_ratio_u256<A, B>(numerator: A, denominator: B) -> Signed<Decimal256>where A: Into<Uint256>, B: Into<Uint256>,
Returns the ratio (nominator / denominator) as a positive Number
pub 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
pub fn from_fixed_u128(amount: u128, places: u32) -> Signed<Decimal256>
pub fn from_fixed_u128(amount: u128, places: u32) -> Signed<Decimal256>
helper to get from native currency to Number e.g. from uusd to UST, as a Decimal
pub 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
pub fn from_unsigned_key_bytes(bytes: [u8; 32]) -> Signed<Decimal256>
pub fn from_unsigned_key_bytes(bytes: [u8; 32]) -> Signed<Decimal256>
Round-tripping with Self::to_unsigned_key_bytes
§impl<T> Signed<T>where
T: UnsignedDecimal,
impl<T> Signed<T>where T: UnsignedDecimal,
pub fn checked_add(self, rhs: Signed<T>) -> Result<Signed<T>, Error>
pub fn checked_add(self, rhs: Signed<T>) -> Result<Signed<T>, Error>
Addition that checks for integer overflow.
pub fn checked_sub(self, rhs: Signed<T>) -> Result<Signed<T>, Error>
pub fn checked_sub(self, rhs: Signed<T>) -> Result<Signed<T>, Error>
Subtraction that checks for underflow
§impl Signed<Decimal256>
impl Signed<Decimal256>
pub fn checked_mul(
self,
rhs: Signed<Decimal256>
) -> Result<Signed<Decimal256>, Error>
pub fn checked_mul( self, rhs: Signed<Decimal256> ) -> Result<Signed<Decimal256>, Error>
Multiplication that checks for integer overflow
pub fn checked_div(
self,
rhs: Signed<Decimal256>
) -> Result<Signed<Decimal256>, Error>
pub fn checked_div( self, rhs: Signed<Decimal256> ) -> Result<Signed<Decimal256>, Error>
Division that checks for underflow and divide-by-zero.
pub fn approx_eq(self, other: Signed<Decimal256>) -> Result<bool, Error>
pub fn approx_eq(self, other: Signed<Decimal256>) -> Result<bool, Error>
equality check with allowance for precision diff
pub fn approx_eq_eps(
self,
other: Signed<Decimal256>,
eps: Signed<Decimal256>
) -> Result<bool, Error>
pub fn approx_eq_eps( self, other: Signed<Decimal256>, eps: Signed<Decimal256> ) -> Result<bool, Error>
equality check with allowance for precision diff
pub fn approx_lt_relaxed(self, other: Signed<Decimal256>) -> Result<bool, Error>
pub fn approx_lt_relaxed(self, other: Signed<Decimal256>) -> Result<bool, Error>
less-than with allowance for precision diff
pub fn approx_gt_relaxed(self, other: Signed<Decimal256>) -> Result<bool, Error>
pub fn approx_gt_relaxed(self, other: Signed<Decimal256>) -> Result<bool, Error>
greater-than with allowance for precision diff
pub fn approx_gt_strict(self, other: Signed<Decimal256>) -> Result<bool, Error>
pub fn approx_gt_strict(self, other: Signed<Decimal256>) -> Result<bool, Error>
greater-than with restriction for precision diff
§impl<T> Signed<T>where
T: UnsignedDecimal,
impl<T> Signed<T>where T: UnsignedDecimal,
pub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Strictly less than 0, returns false on 0
pub fn into_number(self) -> Signed<Decimal256>
pub fn into_number(self) -> Signed<Decimal256>
Convert into a general purpose Number.
pub fn from_number(src: Signed<Decimal256>) -> Signed<T>
pub fn from_number(src: Signed<Decimal256>) -> Signed<T>
convert from a general purpose Number.
pub 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
.
pub 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
§impl Signed<Decimal256>
impl Signed<Decimal256>
pub const MAX: Signed<Decimal256> = _
pub const MAX: Signed<Decimal256> = _
The maximum allowed
pub const MIN: Signed<Decimal256> = _
pub const MIN: Signed<Decimal256> = _
The minimum allowed
pub const ONE: Signed<Decimal256> = _
pub const ONE: Signed<Decimal256> = _
1 as a Number
pub const NEG_ONE: Signed<Decimal256> = _
pub const NEG_ONE: Signed<Decimal256> = _
-1 as a Number
pub const ZERO: Signed<Decimal256> = _
pub const ZERO: Signed<Decimal256> = _
0 as a Number
pub const EPS_E7: Signed<Decimal256> = _
pub const EPS_E7: Signed<Decimal256> = _
Default epsilon used for approximate comparisons
pub const EPS_E6: Signed<Decimal256> = _
pub const EPS_E6: Signed<Decimal256> = _
An alternate epsilon that can be used for approximate comparisons
pub const EPS_E17: Signed<Decimal256> = _
pub const EPS_E17: Signed<Decimal256> = _
Another alternate epsilon that can be used for approximate comparisons where the rounding error is due to the Decimal256 representation as opposed to, say, token precision
§impl<T> Signed<T>where
T: UnsignedDecimal,
impl<T> Signed<T>where T: UnsignedDecimal,
pub fn checked_mul_number(
self,
rhs: Signed<Decimal256>
) -> Result<Signed<T>, Error>
pub fn checked_mul_number( self, rhs: Signed<Decimal256> ) -> Result<Signed<T>, Error>
Multiply by a raw number
§impl<T> Signed<T>where
T: UnsignedDecimal,
impl<T> Signed<T>where T: UnsignedDecimal,
pub fn abs_unsigned(self) -> T
pub fn abs_unsigned(self) -> T
Absolute value, but return the T
underlying type directly
pub fn is_strictly_positive(&self) -> bool
pub fn is_strictly_positive(&self) -> bool
Checks if this number is greater than 0.
pub 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.
pub fn map<U, F>(self, f: F) -> Signed<U>where
U: UnsignedDecimal,
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> Signed<U>where U: UnsignedDecimal, F: FnOnce(T) -> 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.
§impl Signed<Decimal256>
impl Signed<Decimal256>
pub fn to_pyth_price(
&self,
conf: u64,
publish_time: i64
) -> Result<Price, Error>
pub fn to_pyth_price( &self, conf: u64, publish_time: i64 ) -> Result<Price, Error>
Converts a Number into a pyth price the exponent will always be 0 or negative
Trait Implementations§
§impl<T> Add for Signed<T>where
T: UnsignedDecimal,
impl<T> Add for Signed<T>where T: UnsignedDecimal,
§impl<T> Debug for Signed<T>where
T: UnsignedDecimal,
impl<T> Debug for Signed<T>where T: UnsignedDecimal,
§impl<T> Default for Signed<T>where
T: UnsignedDecimal,
impl<T> Default for Signed<T>where T: UnsignedDecimal,
§impl<'de, T> Deserialize<'de> for Signed<T>where
T: UnsignedDecimal,
impl<'de, T> Deserialize<'de> for Signed<T>where T: UnsignedDecimal,
Deserializes as string for serde
§fn deserialize<D>(
deserializer: D
) -> Result<Signed<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Signed<T>, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
§impl<T> Display for Signed<T>where
T: UnsignedDecimal,
impl<T> Display for Signed<T>where T: UnsignedDecimal,
§impl Div<u64> for Signed<Decimal256>
impl Div<u64> for Signed<Decimal256>
§impl Div for Signed<Decimal256>
impl Div for Signed<Decimal256>
§fn div(self, rhs: Signed<Decimal256>) -> <Signed<Decimal256> as Div>::Output
fn div(self, rhs: Signed<Decimal256>) -> <Signed<Decimal256> as Div>::Output
/
operation. Read more§impl<T> From<NonZero<T>> for Signed<T>where
T: UnsignedDecimal,
impl<T> From<NonZero<T>> for Signed<T>where T: UnsignedDecimal,
§impl From<Signed<Decimal256>> for SignedLeverageToNotional
impl From<Signed<Decimal256>> for SignedLeverageToNotional
§fn from(value: Signed<Decimal256>) -> SignedLeverageToNotional
fn from(value: Signed<Decimal256>) -> SignedLeverageToNotional
§impl<T> From<u128> for Signed<T>where
T: UnsignedDecimal,
impl<T> From<u128> for Signed<T>where T: UnsignedDecimal,
§impl<T> From<u64> for Signed<T>where
T: UnsignedDecimal,
impl<T> From<u64> for Signed<T>where T: UnsignedDecimal,
§impl<T> FromStr for Signed<T>where
T: UnsignedDecimal,
impl<T> FromStr for Signed<T>where T: UnsignedDecimal,
§impl<T> JsonSchema for Signed<T>where
T: UnsignedDecimal,
impl<T> JsonSchema for Signed<T>where T: UnsignedDecimal,
§fn schema_name() -> String
fn schema_name() -> String
§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read more§fn json_schema(_: &mut SchemaGenerator) -> Schema
fn json_schema(_: &mut SchemaGenerator) -> Schema
§impl Mul<u64> for Signed<Decimal256>
impl Mul<u64> for Signed<Decimal256>
§impl Mul for Signed<Decimal256>
impl Mul for Signed<Decimal256>
§fn mul(self, rhs: Signed<Decimal256>) -> <Signed<Decimal256> as Mul>::Output
fn mul(self, rhs: Signed<Decimal256>) -> <Signed<Decimal256> as Mul>::Output
*
operation. Read more§impl<T> Neg for Signed<T>where
T: UnsignedDecimal,
impl<T> Neg for Signed<T>where T: UnsignedDecimal,
§impl<T> Ord for Signed<T>where
T: UnsignedDecimal,
impl<T> Ord for Signed<T>where T: UnsignedDecimal,
§impl<T> PartialOrd for Signed<T>where
T: UnsignedDecimal,
impl<T> PartialOrd for Signed<T>where T: UnsignedDecimal,
§fn partial_cmp(&self, other: &Signed<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &Signed<T>) -> Option<Ordering>
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 more§impl<T> Serialize for Signed<T>where
T: UnsignedDecimal,
impl<T> Serialize for Signed<T>where T: UnsignedDecimal,
Serializes as a string for serde
§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
§impl<T> Sub for Signed<T>where
T: UnsignedDecimal,
impl<T> Sub for Signed<T>where T: UnsignedDecimal,
§impl TryFrom<&str> for Signed<Collateral>
impl TryFrom<&str> for Signed<Collateral>
§impl TryFrom<&str> for Signed<Decimal256>
impl TryFrom<&str> for Signed<Decimal256>
§impl TryFrom<&str> for Signed<FarmingToken>
impl TryFrom<&str> for Signed<FarmingToken>
§impl TryFrom<Price> for Signed<Decimal256>
impl TryFrom<Price> for Signed<Decimal256>
§impl<T> TryFrom<Signed<T>> for NonZero<T>where
T: UnsignedDecimal,
impl<T> TryFrom<Signed<T>> for NonZero<T>where T: UnsignedDecimal,
§impl TryFrom<String> for Signed<Collateral>
impl TryFrom<String> for Signed<Collateral>
§impl TryFrom<String> for Signed<Decimal256>
impl TryFrom<String> for Signed<Decimal256>
§impl TryFrom<String> for Signed<FarmingToken>
impl TryFrom<String> for Signed<FarmingToken>
impl<T> Copy for Signed<T>where T: Copy,
impl<T> Eq for Signed<T>where T: Eq,
impl<T> StructuralEq for Signed<T>
impl<T> StructuralPartialEq for Signed<T>
Auto Trait Implementations§
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 more