pub struct PositiveDecimal(/* private fields */);Expand description
A decimal value that must be positive. Wraps rust_decimal::Decimal.
ⓘ
use rust_decimal::Decimal;
use bullet_rust_sdk::PositiveDecimal;
let price = PositiveDecimal::try_from(Decimal::from(50000))?;
let qty = PositiveDecimal::try_from(Decimal::new(1, 3))?; // 0.001Implementations§
Source§impl PositiveDecimal
impl PositiveDecimal
Sourcepub const ZERO: PositiveDecimal
pub const ZERO: PositiveDecimal
The smallest positive value that can be represented by PositiveDecimal.
pub const ONE: PositiveDecimal
pub const TWO: PositiveDecimal
pub const TEN: PositiveDecimal
pub const ONE_HUNDRED: PositiveDecimal
pub const MAX: PositiveDecimal
pub fn new(value: Decimal) -> Option<PositiveDecimal>
pub fn to_fixed(&self, rounding_mode: RoundingMode) -> FixedPositiveDecimal
pub fn as_dec(&self) -> Decimal
pub fn is_zero(&self) -> bool
pub fn fract(&self) -> Decimal
pub fn try_pow_i64(&self, v: i64) -> Result<PositiveDecimal, ArithmeticError>
pub fn try_with_precision( &self, precision: i64, ) -> Result<PositiveDecimal, ArithmeticError>
Sourcepub fn saturating_sub(self, v: impl Into<Decimal>) -> PositiveDecimal
pub fn saturating_sub(self, v: impl Into<Decimal>) -> PositiveDecimal
Performs a saturating subtraction for PositiveDecimal, this is for intentional saturating subtractions hence no warnings We don’t return a result because we know the saturating subtraction result will always be non-negative
Trait Implementations§
Source§impl Add for PositiveDecimal
impl Add for PositiveDecimal
Source§type Output = PositiveDecimal
type Output = PositiveDecimal
The resulting type after applying the
+ operator.Source§fn add(self, other: PositiveDecimal) -> <PositiveDecimal as Add>::Output
fn add(self, other: PositiveDecimal) -> <PositiveDecimal as Add>::Output
Performs the
+ operation. Read moreSource§impl BorshDeserialize for PositiveDecimal
impl BorshDeserialize for PositiveDecimal
fn deserialize_reader<R>(reader: &mut R) -> Result<PositiveDecimal, Error>where
R: Read,
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for PositiveDecimal
impl BorshSerialize for PositiveDecimal
Source§impl Clone for PositiveDecimal
impl Clone for PositiveDecimal
Source§fn clone(&self) -> PositiveDecimal
fn clone(&self) -> PositiveDecimal
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PositiveDecimal
impl Debug for PositiveDecimal
Source§impl Default for PositiveDecimal
impl Default for PositiveDecimal
Source§fn default() -> PositiveDecimal
fn default() -> PositiveDecimal
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for PositiveDecimal
impl<'de> Deserialize<'de> for PositiveDecimal
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<PositiveDecimal, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PositiveDecimal, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for PositiveDecimal
impl Display for PositiveDecimal
Source§impl Div for PositiveDecimal
impl Div for PositiveDecimal
Source§type Output = PositiveDecimal
type Output = PositiveDecimal
The resulting type after applying the
/ operator.Source§fn div(self, other: PositiveDecimal) -> <PositiveDecimal as Div>::Output
fn div(self, other: PositiveDecimal) -> <PositiveDecimal as Div>::Output
Performs the
/ operation. Read moreSource§impl From<FixedPositiveDecimal> for PositiveDecimal
impl From<FixedPositiveDecimal> for PositiveDecimal
Source§fn from(value: FixedPositiveDecimal) -> PositiveDecimal
fn from(value: FixedPositiveDecimal) -> PositiveDecimal
Converts to this type from the input type.
Source§impl From<u16> for PositiveDecimal
impl From<u16> for PositiveDecimal
Source§fn from(value: u16) -> PositiveDecimal
fn from(value: u16) -> PositiveDecimal
Converts to this type from the input type.
Source§impl From<u32> for PositiveDecimal
impl From<u32> for PositiveDecimal
Source§fn from(value: u32) -> PositiveDecimal
fn from(value: u32) -> PositiveDecimal
Converts to this type from the input type.
Source§impl From<u64> for PositiveDecimal
impl From<u64> for PositiveDecimal
Source§fn from(value: u64) -> PositiveDecimal
fn from(value: u64) -> PositiveDecimal
Converts to this type from the input type.
Source§impl From<u8> for PositiveDecimal
impl From<u8> for PositiveDecimal
Source§fn from(value: u8) -> PositiveDecimal
fn from(value: u8) -> PositiveDecimal
Converts to this type from the input type.
Source§impl FromStr for PositiveDecimal
impl FromStr for PositiveDecimal
Source§type Err = ConfigError
type Err = ConfigError
The associated error which can be returned from parsing.
Source§fn from_str(
s: &str,
) -> Result<PositiveDecimal, <PositiveDecimal as FromStr>::Err>
fn from_str( s: &str, ) -> Result<PositiveDecimal, <PositiveDecimal as FromStr>::Err>
Parses a string
s to return a value of this type. Read moreSource§impl Hash for PositiveDecimal
impl Hash for PositiveDecimal
Source§impl JsonSchema for PositiveDecimal
impl JsonSchema for PositiveDecimal
Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref keyword. Read moreSource§impl Mul for PositiveDecimal
impl Mul for PositiveDecimal
Source§type Output = PositiveDecimal
type Output = PositiveDecimal
The resulting type after applying the
* operator.Source§fn mul(self, other: PositiveDecimal) -> <PositiveDecimal as Mul>::Output
fn mul(self, other: PositiveDecimal) -> <PositiveDecimal as Mul>::Output
Performs the
* operation. Read moreSource§impl Neg for PositiveDecimal
impl Neg for PositiveDecimal
Source§impl Ord for PositiveDecimal
impl Ord for PositiveDecimal
Source§fn cmp(&self, other: &PositiveDecimal) -> Ordering
fn cmp(&self, other: &PositiveDecimal) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for PositiveDecimal
impl PartialEq for PositiveDecimal
Source§impl PartialOrd for PositiveDecimal
impl PartialOrd for PositiveDecimal
Source§impl Serialize for PositiveDecimal
impl Serialize for PositiveDecimal
Source§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,
Serialize this value into the given Serde serializer. Read more
Source§impl Sub for PositiveDecimal
impl Sub for PositiveDecimal
Source§impl TryDecimalOps for PositiveDecimal
impl TryDecimalOps for PositiveDecimal
fn try_from_str(value: &str) -> Result<PositiveDecimal, ConfigError>
fn try_add( self, v: impl Into<Decimal>, ) -> Result<PositiveDecimal, ArithmeticError>
fn try_sub( self, v: impl Into<Decimal>, ) -> Result<PositiveDecimal, ArithmeticError>
fn try_mul( self, v: impl Into<Decimal>, ) -> Result<PositiveDecimal, ArithmeticError>
fn try_div( self, v: impl Into<Decimal>, ) -> Result<PositiveDecimal, ArithmeticError>
fn try_exp(self) -> Result<PositiveDecimal, ArithmeticError>
Source§impl TryFrom<Decimal> for PositiveDecimal
impl TryFrom<Decimal> for PositiveDecimal
Source§type Error = ConfigError
type Error = ConfigError
The type returned in the event of a conversion error.
Source§fn try_from(value: Decimal) -> Result<PositiveDecimal, ConfigError>
fn try_from(value: Decimal) -> Result<PositiveDecimal, ConfigError>
Performs the conversion.
Source§impl UniversalWallet for PositiveDecimal
impl UniversalWallet for PositiveDecimal
Source§fn scaffold() -> Item<IndexLinking>
fn scaffold() -> Item<IndexLinking>
Generate the “scaffolding” of the item. If the item is a primtive, this is just the corresponding primtive.
If the type is composed of other types, this is the container with all links set to
Link::Placeholder.Source§fn get_child_links(schema: &mut Schema) -> Vec<Link>
fn get_child_links(schema: &mut Schema) -> Vec<Link>
Ensure that each type contained in the outer type (i.e. the type of each struct/tuple field) is added to the schema,
and return a
Link connecting the child to the parent. Read moreSource§fn get_child_templates(schema: &mut Schema) -> TransactionTemplateSet
fn get_child_templates(schema: &mut Schema) -> TransactionTemplateSet
Empty by default
When derived by the macro, builds a template set from annotations on the fields + the field
types’ own get_child_templates()
Source§fn write_schema(schema: &mut Schema) -> Link
fn write_schema(schema: &mut Schema) -> Link
Writes the type to the schema if it is not already present and returns a link to it. Read more
Source§fn make_root_of(schema: &mut Schema)
fn make_root_of(schema: &mut Schema)
Writes the type and all its children to the schema, if not already present, and sets the
type as a root type. Generates any templates defined on that type.
Source§fn make_linkable(schema: &mut Schema) -> Link
fn make_linkable(schema: &mut Schema) -> Link
Gets a link to the type, writing the type to the schema if necessary.
Source§fn id_override() -> Option<ItemId>
fn id_override() -> Option<ItemId>
Override the type ID of the item. This should typically not be written by hand. Instead,
use the
OverrideSchema trait.impl Copy for PositiveDecimal
impl Eq for PositiveDecimal
impl StructuralPartialEq for PositiveDecimal
Auto Trait Implementations§
impl Freeze for PositiveDecimal
impl RefUnwindSafe for PositiveDecimal
impl Send for PositiveDecimal
impl Sync for PositiveDecimal
impl Unpin for PositiveDecimal
impl UnsafeUnpin for PositiveDecimal
impl UnwindSafe for PositiveDecimal
Blanket Implementations§
Source§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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.