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>

source

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

source

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

source

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

source

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

source

pub fn from_unsigned_key_bytes(bytes: [u8; 32]) -> Self

Round-tripping with Self::to_unsigned_key_bytes

source§

impl<T: UnsignedDecimal> Signed<T>

source

pub fn checked_add(self, rhs: Self) -> Result<Self>

Addition that checks for integer overflow.

source

pub fn checked_sub(self, rhs: Self) -> Result<Self>

Subtraction that checks for underflow

source§

impl Signed<Decimal256>

source

pub fn checked_mul(self, rhs: Self) -> Result<Self>

Multiplication that checks for integer overflow

source

pub fn checked_div(self, rhs: Self) -> Result<Self>

Division that checks for underflow and divide-by-zero.

source

pub fn approx_eq(self, other: Number) -> Result<bool>

equality check with allowance for precision diff

source

pub fn approx_eq_eps(self, other: Number, eps: Number) -> Result<bool>

equality check with allowance for precision diff

source

pub fn approx_lt_relaxed(self, other: Number) -> Result<bool>

less-than with allowance for precision diff

source

pub fn approx_gt_relaxed(self, other: Number) -> Result<bool>

greater-than with allowance for precision diff

source

pub fn approx_gt_strict(self, other: Number) -> Result<bool>

greater-than with restriction for precision diff

source§

impl<T: UnsignedDecimal> Signed<T>

source

pub fn is_negative(&self) -> bool

Strictly less than 0, returns false on 0

source

pub fn into_number(self) -> Signed<Decimal256>

Convert into a general purpose Number.

source

pub fn from_number(src: Signed<Decimal256>) -> Self

convert from a general purpose Number.

source

pub fn zero() -> Self

The value 0

source

pub fn two() -> Self

The value 2

source

pub fn try_into_non_negative_value(self) -> Option<T>

If the value is positive or zero, return the inner T. Otherwise return None.

source

pub fn try_into_non_zero(self) -> Option<NonZero<T>>

Try to convert into a non-zero value

source§

impl Signed<Decimal256>

source

pub const MAX: Self = _

The maximum allowed

source

pub const MIN: Number = _

The minimum allowed

source

pub const ONE: Number = _

1 as a Number

source

pub const NEG_ONE: Number = _

-1 as a Number

source

pub const ZERO: Number = _

0 as a Number

source

pub const EPS_E7: Number = _

Default epsilon used for approximate comparisons

source

pub const EPS_E6: Number = _

An alternate epsilon that can be used for approximate comparisons

source

pub const EPS_E17: Number = _

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

source§

impl<T: UnsignedDecimal> Signed<T>

source

pub fn checked_mul_number(self, rhs: Signed<Decimal256>) -> Result<Self>

Multiply by a raw number

source§

impl<T: UnsignedDecimal> Signed<T>

source

pub fn abs(self) -> Self

absolute value

source

pub fn abs_unsigned(self) -> T

Absolute value, but return the T underlying type directly

source

pub fn is_strictly_positive(&self) -> bool

Checks if this number is greater than 0.

source

pub fn is_positive_or_zero(&self) -> bool

Checks if this number is greater than or equal to 0.

source

pub fn is_zero(&self) -> bool

Is the value 0?

source

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

pub fn try_map<E, U: UnsignedDecimal, F: FnOnce(T) -> Result<U, E>>( self, f: F, ) -> Result<Signed<U>, E>

Like map but may fail

source§

impl Signed<Decimal256>

source

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>

§

type Output = Result<Signed<T>, Error>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Clone> Clone for Signed<T>

source§

fn clone(&self) -> Signed<T>

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<T: UnsignedDecimal> Debug for Signed<T>

source§

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

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

impl<T: UnsignedDecimal> Default for Signed<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: UnsignedDecimal> Display for Signed<T>

source§

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

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

impl<T: UnsignedDecimal> From<NonZero<T>> for Signed<T>

source§

fn from(src: NonZero<T>) -> Self

Converts to this type from the input type.
source§

impl From<Signed<Decimal256>> for SignedLeverageToNotional

source§

fn from(value: Signed<Decimal256>) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Signed<T>

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl<T: UnsignedDecimal> From<u128> for Signed<T>

source§

fn from(val: u128) -> Self

Converts to this type from the input type.
source§

impl<T: UnsignedDecimal> From<u64> for Signed<T>

source§

fn from(val: u64) -> Self

Converts to this type from the input type.
source§

impl<T: UnsignedDecimal> FromStr for Signed<T>

source§

fn from_str(input: &str) -> Result<Self>

Converts the decimal string to a Number Possible inputs: “1.23”, “1”, “000012”, “1.123000000”, “-1.23” Disallowed: “”, “.23”

This never performs any kind of rounding. More than 18 fractional digits, even zeros, result in an error.

§

type Err = Error

The associated error which can be returned from parsing.
source§

impl<T: UnsignedDecimal> JsonSchema for Signed<T>

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

fn json_schema(_: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
source§

impl<T: UnsignedDecimal> Neg for Signed<T>

§

type Output = Signed<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl<T: UnsignedDecimal> Ord for Signed<T>

source§

fn cmp(&self, other: &Self) -> 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 + PartialOrd,

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

impl<T: PartialEq> PartialEq for Signed<T>

source§

fn eq(&self, other: &Signed<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: UnsignedDecimal> PartialOrd for Signed<T>

source§

fn partial_cmp(&self, other: &Self) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: UnsignedDecimal> Serialize for Signed<T>

Serializes as a string for serde

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: UnsignedDecimal> Sub for Signed<T>

§

type Output = Result<Signed<T>, Error>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl TryFrom<&str> for Signed<Base>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for Signed<Collateral>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for Signed<FarmingToken>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for Signed<LockdropShares>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for Signed<LpToken>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for Signed<LvnToken>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for Signed<Notional>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for Signed<Quote>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for Signed<Usd>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
source§

impl<T: UnsignedDecimal> TryFrom<Signed<T>> for NonZero<T>

§

type Error = Error

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

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

Performs the conversion.
source§

impl TryFrom<String> for Signed<Base>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Signed<Collateral>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Signed<FarmingToken>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Signed<LockdropShares>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Signed<LpToken>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Signed<LvnToken>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Signed<Notional>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Signed<Quote>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<String> for Signed<Usd>

§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.
source§

impl<T: Copy> Copy for Signed<T>

source§

impl<T: Eq> Eq for Signed<T>

source§

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§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts 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
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: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> QueryResultExt for T
where T: Serialize,

source§

fn query_result(&self) -> Result<Binary, Error>

Convert the value to its JSON representation
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,