This crate provides a number of conversion traits with more specific semantics than those provided by
The goal with the traits provided here is to be more specific about what generic code can rely on, as well as provide reasonably self-describing alternatives to the standard
Into traits. For example, the although
T: From<U> might be satisfied in generic code, this says nothing about what kind of conversion that represents.
Into provide no facility for a conversion failing, meaning that implementations may need to choose between conversions that may not be valid, or panicking; neither option is appealing in general.
conv is compatible with Rust 1.2 and higher.
# extern crate conv; # use *; #
- Added integer ↔
- Added missing
- Fixed the error type of
usizefor 64-bit targets.
- Change to
unwrap_okfor better codegen (thanks bluss).
- Fix for Rust breaking change (code in question was dodgy anyway; thanks m4rw3r).
- Added an
Errorconstraint to all
Errassociated types. This will break any user-defined conversions where the
Errtype does not implement
- Renamed the
NegOverflowrespectively. In the context of floating point conversions, "underflow" usually means the value was too close to zero to correctly represent.
ConvUtil::into_as<Dst>as a shortcut for
Saturate::saturate, which can saturate
Results arising from over/underflow.
- Changed all error types to include the original input as payload. This breaks pretty much everything. Sorry about that. On the bright side, there's now no downside to using the conversion traits for non-
- Added the normal rounding modes for float → int approximations:
ApproxWithis now subsumed by a pair of extension traits (
ConvAsUtil), that also have shortcuts for
ValueIntoso that you can specify the destination type on the method.