New trait: core::convert::IntoUnderlying

I've put together an RFC proposing a new trait in core for converting types to their underlying type (specifically for converting primitive enums to their underlying repr, but not limited to that case). I'm particularly interested in this as a step towards making as conversions less prevalent in the language, but it stands alone as a proposal.

I'd be interested in feedback and bikeshedding, either on the PR, or in this thread.

AsUnderlying would better signal the connection to as and the intended "free" nature of the conversion.

The derive macro could also support struct types where the struct has a single field.

I feel #[repr(transparent)] structs would be a more precise future possibility. It fills a similar role to #[repr({integer})] in that they both result in a transmutable, ABI-conforming data structure.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.