Skip to main content

DecimalCast

Trait DecimalCast 

pub trait DecimalCast: Sized {
    // Required methods
    fn to_i32(self) -> Option<i32>;
    fn to_i64(self) -> Option<i64>;
    fn to_i128(self) -> Option<i128>;
    fn to_i256(self) -> Option<i256>;
    fn from_decimal<T>(n: T) -> Option<Self>
       where T: DecimalCast;
    fn from_f64(n: f64) -> Option<Self>;
}
Expand description

A utility trait that provides checked conversions between decimal types inspired by NumCast

Required Methods§

fn to_i32(self) -> Option<i32>

Convert the decimal to an i32

fn to_i64(self) -> Option<i64>

Convert the decimal to an i64

fn to_i128(self) -> Option<i128>

Convert the decimal to an i128

fn to_i256(self) -> Option<i256>

Convert the decimal to an i256

fn from_decimal<T>(n: T) -> Option<Self>
where T: DecimalCast,

Convert a decimal from a decimal

fn from_f64(n: f64) -> Option<Self>

Convert a decimal from a f64

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl DecimalCast for i32

§

fn to_i32(self) -> Option<i32>

§

fn to_i64(self) -> Option<i64>

§

fn to_i128(self) -> Option<i128>

§

fn to_i256(self) -> Option<i256>

§

fn from_decimal<T>(n: T) -> Option<i32>
where T: DecimalCast,

§

fn from_f64(n: f64) -> Option<i32>

§

impl DecimalCast for i64

§

fn to_i32(self) -> Option<i32>

§

fn to_i64(self) -> Option<i64>

§

fn to_i128(self) -> Option<i128>

§

fn to_i256(self) -> Option<i256>

§

fn from_decimal<T>(n: T) -> Option<i64>
where T: DecimalCast,

§

fn from_f64(n: f64) -> Option<i64>

§

impl DecimalCast for i128

§

fn to_i32(self) -> Option<i32>

§

fn to_i64(self) -> Option<i64>

§

fn to_i128(self) -> Option<i128>

§

fn to_i256(self) -> Option<i256>

§

fn from_decimal<T>(n: T) -> Option<i128>
where T: DecimalCast,

§

fn from_f64(n: f64) -> Option<i128>

Implementors§