Skip to main content

NumericConversion

Trait NumericConversion 

Source
pub trait NumericConversion<T> {
    // Required methods
    fn try_convert(self) -> Option<T>;
    fn convert_or(self, default: T) -> T;
    fn convert(self) -> T;
}
Expand description

Conversion between different numeric types

Required Methods§

Source

fn try_convert(self) -> Option<T>

Try to convert to the target type

Source

fn convert_or(self, default: T) -> T

Convert to the target type, or a default value if conversion fails

Source

fn convert(self) -> T

Convert to the target type, or panic if conversion fails

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<F, T> NumericConversion<T> for F
where F: NumCast, T: NumCast,

Implement NumericConversion for all types that implement NumCast