Trait ToFixed

Source
pub trait ToFixed: Sized + Debug {
    // Provided methods
    fn to_fixed<T: FixedPointValue + From<Self>>(self) -> FixedPoint<T> { ... }
    fn try_to_fixed<T: FixedPointValue + TryFrom<Self>>(
        self,
    ) -> Result<FixedPoint<T>> { ... }
}
Expand description

A type that can convert to FixedPoint<T> via .to_fixed(), and attempt conversion to FixedPoint<T> via .try_to_fixed().

Provided Methods§

Source

fn to_fixed<T: FixedPointValue + From<Self>>(self) -> FixedPoint<T>

Converts the value to a FixedPoint<T> instance, first converting the value to the underlying T type if necessary.

§Example
let a: FixedPoint<U256> = 100_u128.to_fixed();
let b: FixedPoint<I256> = 100_i128.to_fixed();

Using ‘turbofish’ syntax:

let a = 100_u128.to_fixed::<U256>();
let b = 100_i128.to_fixed::<I256>();
Source

fn try_to_fixed<T: FixedPointValue + TryFrom<Self>>( self, ) -> Result<FixedPoint<T>>

Attempts to convert the value to a FixedPoint<T> instance, first converting the value to the underlying T type if necessary.

§Example
let b: FixedPoint<I256> = U256::from(100).try_to_fixed().unwrap();

Using ‘turbofish’ syntax:

let a = 100.try_to_fixed::<U256>();  // -> Ok(FixedPoint<U256>)
let b = -100.try_to_fixed::<U256>(); // -> Err(...)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Sized + Debug> ToFixed for T