pub struct Signed<T> { /* private fields */ }
Expand description

Wrap up any UnsignedDecimal to provide negative values too.

Implementations§

§

impl Signed<Decimal256>

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>

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>

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

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>

Round-tripping with Self::to_unsigned_key_bytes

§

impl<T> Signed<T>where T: UnsignedDecimal,

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>

Subtraction that checks for underflow

§

impl Signed<Decimal256>

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>

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

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>

equality check with allowance for precision diff

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>

greater-than with allowance for precision diff

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,

pub fn is_negative(&self) -> bool

Strictly less than 0, returns false on 0

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

Convert into a general purpose Number.

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

convert from a general purpose Number.

pub fn zero() -> Signed<T>

The value 0

pub fn two() -> Signed<T>

The value 2

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

Try to convert into a non-zero value

§

impl Signed<Decimal256>

pub const MAX: Signed<Decimal256> = _

The maximum allowed

pub const MIN: Signed<Decimal256> = _

The minimum allowed

pub const ONE: Signed<Decimal256> = _

1 as a Number

pub const NEG_ONE: Signed<Decimal256> = _

-1 as a Number

pub const ZERO: Signed<Decimal256> = _

0 as a Number

pub const EPS_E7: Signed<Decimal256> = _

Default epsilon used for approximate comparisons

pub const EPS_E6: Signed<Decimal256> = _

An alternate epsilon that can be used for approximate comparisons

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,

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,

pub fn abs(self) -> Signed<T>

absolute value

pub fn abs_unsigned(self) -> T

Absolute value, but return the T underlying type directly

pub fn is_strictly_positive(&self) -> bool

Checks if this number is greater than 0.

pub fn is_positive_or_zero(&self) -> bool

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

pub fn is_zero(&self) -> bool

Is the value 0?

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.

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

Like map but may fail

§

impl Signed<Decimal256>

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,

§

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

The resulting type after applying the + operator.
§

fn add(self, rhs: Signed<T>) -> <Signed<T> as Add>::Output

Performs the + operation. Read more
§

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

§

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
§

impl<T> Debug for Signed<T>where T: UnsignedDecimal,

§

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

Formats the value using the given formatter. Read more
§

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

§

fn default() -> Signed<T>

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

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

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

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

§

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

Formats the value using the given formatter. Read more
§

impl Div<u64> for Signed<Decimal256>

§

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

The resulting type after applying the / operator.
§

fn div(self, rhs: u64) -> <Signed<Decimal256> as Div<u64>>::Output

Performs the / operation. Read more
§

impl Div for Signed<Decimal256>

§

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

The resulting type after applying the / operator.
§

fn div(self, rhs: Signed<Decimal256>) -> <Signed<Decimal256> as Div>::Output

Performs the / operation. Read more
§

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

§

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

Converts to this type from the input type.
§

impl From<Signed<Decimal256>> for SignedLeverageToNotional

§

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

Converts to this type from the input type.
§

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

§

fn from(value: T) -> Signed<T>

Converts to this type from the input type.
§

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

§

fn from(val: u128) -> Signed<T>

Converts to this type from the input type.
§

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

§

fn from(val: u64) -> Signed<T>

Converts to this type from the input type.
§

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

§

fn from_str(input: &str) -> Result<Signed<T>, Error>

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

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

§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
§

fn is_referenceable() -> bool

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

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
§

impl Mul<u64> for Signed<Decimal256>

§

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

The resulting type after applying the * operator.
§

fn mul(self, rhs: u64) -> <Signed<Decimal256> as Mul<u64>>::Output

Performs the * operation. Read more
§

impl Mul for Signed<Decimal256>

§

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

The resulting type after applying the * operator.
§

fn mul(self, rhs: Signed<Decimal256>) -> <Signed<Decimal256> as Mul>::Output

Performs the * operation. Read more
§

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

§

type Output = Signed<T>

The resulting type after applying the - operator.
§

fn neg(self) -> Signed<T>

Performs the unary - operation. Read more
§

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

§

fn cmp(&self, other: &Signed<T>) -> Ordering

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
§

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

§

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

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

§

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

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,

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

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

§

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

The resulting type after applying the - operator.
§

fn sub(self, rhs: Signed<T>) -> <Signed<T> as Sub>::Output

Performs the - operation. Read more
§

impl TryFrom<&str> for Signed<Base>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<Base>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<Collateral>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<Collateral>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<Decimal256>

§

type Error = Error

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

fn try_from(val: &str) -> Result<Signed<Decimal256>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<FarmingToken>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<FarmingToken>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<LockdropShares>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<LockdropShares>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<LpToken>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<LpToken>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<LvnToken>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<LvnToken>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<Notional>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<Notional>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<Quote>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<Quote>, Error>

Performs the conversion.
§

impl TryFrom<&str> for Signed<Usd>

§

type Error = Error

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

fn try_from(value: &str) -> Result<Signed<Usd>, Error>

Performs the conversion.
§

impl TryFrom<Price> for Signed<Decimal256>

§

type Error = Error

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

fn try_from( price: Price ) -> Result<Signed<Decimal256>, <Signed<Decimal256> as TryFrom<Price>>::Error>

Performs the conversion.
§

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

§

type Error = Error

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

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

Performs the conversion.
§

impl TryFrom<String> for Signed<Base>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<Base>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<Collateral>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<Collateral>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<Decimal256>

§

type Error = Error

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

fn try_from(val: String) -> Result<Signed<Decimal256>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<FarmingToken>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<FarmingToken>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<LockdropShares>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<LockdropShares>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<LpToken>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<LpToken>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<LvnToken>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<LvnToken>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<Notional>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<Notional>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<Quote>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<Quote>, Error>

Performs the conversion.
§

impl TryFrom<String> for Signed<Usd>

§

type Error = Error

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

fn try_from(value: String) -> Result<Signed<Usd>, Error>

Performs the conversion.
§

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§

source§

impl<T> Any for Twhere 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) -> Twhere 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 Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

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

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

§

impl<T> QueryResultExt for Twhere T: Serialize,

§

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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.
source§

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