On 13-02-28 09:18 PM, Patrick Walton wrote:
> There is currently a feature whereby custom enum variant discriminants
> can be specified:
>
> pub enum Foo {
> Bar = 1,
> Baz = 2,
> Boo = 3,
> }
>
> The sole use of this is casting from the enum to an int:
It's also to represent enums known-to-C++ with the same values when
projected into rust types.
> This feature currently doesn't really meet people's needs. Chief among
> the issues are:
>
> 1. Only ints are supported, but many enums want to correspond to
> different sizes of types.
This much I think we need to address generally via explicit control over
packing. Especially on x86, _most_ of our enums should be bytes at most.
https://github.com/mozilla/rust/issues/1704
> 2. Only casting *from* an enum value is supported, not casting *to* an
> enum value. Casting to an enum value is not supported because this is a
> partial operation.
Casting _to_ is permitted currently via transmute, which is probably a
fine place to leave it. I agree it'd be nice to provide an auto_enum
syntax extension that defines a bad-value condition, and produces a
.from_int() safe function that hits that condition when given a bad integer.
> 3. There is no way to have multiple values correspond to a single enum
> variant.
Is there in C++? The point of this feature has always been (to my mind)
emulation of C++ where sensible.
-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev