Commit Graph

7 Commits

Author SHA1 Message Date
Josh Stone d2bf4e04e4 Run cargo fmt 2018-07-12 17:09:22 -07:00
Josh Stone 60924ecc70 add test newtype_to_primitive 2018-06-20 13:49:57 -07:00
Josh Stone d968efbc76 Avoid `as` casts in default FromPrimitive methods
Particularly, the default `from_f64` used `n as i64`, which has
undefined behavior on overflow, kind of defeating the purpose here.
Now we use a checked `to_i64()` for this, and even try `to_u64()` as a
fallback for completeness.

(All of the primitive implementations already do better, at least.)
2018-06-20 13:05:03 -07:00
Josh Stone 51f6c57c4b Automatically detect support for i128/u128 2018-05-11 15:50:48 -07:00
Josh Stone bbbc2bd1d7 impl 128-bit numeric casts
This includes new conditional methods `ToPrimitive::{to_i128,to_u128}`
and `FromPrimitive::{from_i128,from_u128}`.  Since features can only be
additive, these methods must not cause a breaking change to anyone when
enabled -- thus they have a default implementation that converts through
64-bit values.  Types that can do better with a full 128-bit integer,
like bigint or floating-point, will probably want to override these.
2018-05-07 12:28:53 -07:00
Alex Crichton a6a399d52e Enable testing on stable Rust 2015-05-19 09:22:06 -07:00
Erick Tryzelaar f4a69a6f01 Export the #[derive(FromPrimitive)] from rust proper
This changes the name to #[derive(NumFromPrimitive)]
in order to not conflict with the libsyntax macro.
2015-04-12 11:19:48 -07:00