Crate num_to

Crate num_to 

Source
Expand description

This crate provides traits [To{type}] and [As{type}] providing methods [to_{type}] and [as_{type}] for converting numbers between types without using [as] casts. The rules for these names are as follows. Methods named [as_{type}] will always convert the value losslessly producing an exact result, whereas [to_{type]] are possibly lossy but will always convert to the nearest value of the result type during integer-integer conversions, and for conversions involving floating-point values, the result is the same as that of an [as] cast.

Whenever an [As] trait is implemented, the corresponding [To] trait is also implemented, and has the same behavior.

Existence of AsUsize and AsIsize for a particular type is target architecture dependent, so usage of these traits is discouraged.

[use num-to::*;] will include only the 14 [As] traits, 14 [To] traits and nothing else.

Traitsยง

AsF32
AsF64
AsI8
AsI16
AsI32
AsI64
AsI128
AsIsize
AsU8
AsU16
AsU32
AsU64
AsU128
AsUsize
ToF32
ToF64
ToI8
ToI16
ToI32
ToI64
ToI128
ToIsize
ToU8
ToU16
ToU32
ToU64
ToU128
ToUsize