Trait easy_cast::Conv [−][src]
Like From
, but supporting potentially-fallible conversions
This trait is intended to replace many uses of the as
keyword for
conversions, though not all.
Very roughly, it is T::try_from(x).unwrap()
, restricted to numeric
conversions (or like From
but with more assumptions).
- Conversions should preserve values precisely
- Conversions should succeed, but may fail (panic)
- We assume that
isize
andusize
are 32 or 64 bits
Fallible conversions are allowed. In Debug builds failure must always panic but in Release builds this is not required (similar to overflow checks on integer arithmetic).
Note that you may not want to use this where loss of precision is
acceptable, e.g. if an approximate conversion x as f64
suffices.