but the way I see it is, the as keyword plays too many roles in the language, including all sorts of integral casts which are not making Rust more robust than C/C++.
We should have something like e.into() for enum-to-integral conversion and prefer it over the as keyword whenever possible, so that we can more carefully verify the remaining occurrences of the as keyword.
This way you only have one occurrence of as i32 to review. Everything else can use .into()
(You could also implement std::convert::Into<i32> if you want)
How about a #[derive(Into)] that only works on repr(inttype) enums and it will implement Into<inttype> (i.e. the same type that was specified in the repr)?
I like the Ida of implementing Into for such types, through instead of having some "special" Into I think it would be nice, if all repr(<inttype>) repr's would imply that a impl for Into is generated.
But this might lead to some problems when the actual repr is more of a implementation detail (e.g. with a C interface) and some Into<inttype> should be implemented witch does not directly represents the underlying value (but then having such a structure is generally a bad idea I think)
Another question is if another .into() is the best choice of name or if it might make sens to show that this is "just" the internal repr of the enum, e.g. .into_raw() or so. Having a explicity method name for this as-usage would prevent the problem mentioned above and enable a automatic implementation of the respecting trait. Oh, and it fits with the into_raw methods of Box, and CString witch do roughly the same in a situation where as cannot be used.