]> git.lizzy.rs Git - rust.git/commit
auto merge of #9250 : erickt/rust/num, r=erickt
authorbors <bors@rust-lang.org>
Sat, 5 Oct 2013 21:26:44 +0000 (14:26 -0700)
committerbors <bors@rust-lang.org>
Sat, 5 Oct 2013 21:26:44 +0000 (14:26 -0700)
commit2733b189ac60cea541fbf80e5839e5027ffc9fbf
treeb9fcc58a2f736f292eb32de9553843c99f91f32d
parent0c388be8d1988a966ef62c545b996b9da0f71e93
parent0e8ad4d8a2f23206c723137d765027a7acd97837
auto merge of #9250 : erickt/rust/num, r=erickt

This PR solves one of the pain points with c-style enums. Simplifies writing a fn to convert from an int/uint to an enum. It does this through a `#[deriving(FromPrimitive)]` syntax extension.

Before this is committed though, we need to discuss if `ToPrimitive`/`FromPrimitive` has the right design (cc #4819). I've changed all the `.to_int()` and `from_int()` style functions to return `Option<int>` so we can handle partial functions. For this PR though only enums and `extra::num::bigint::*` take advantage of returning None for unrepresentable values. In the long run it'd be better if `i64.to_i8()` returned `None` if the value was too large, but I'll save this for a future PR.

Closes #3868.
src/libstd/rand/mod.rs