Feature gate: #![feature(enum_as_repr)]
This is a tracking issue for traits to convert primitive enums into their repr (core::enums::AsRepr), and attempt to convert reprs into primitive enums (core::enums::FromRepr). AsRepr is automatically implemented for all relevant enum types, as well as std::mem::Discriminant, and FromRepr may be derived.
Public API
// core::enums
// Automatically implemented for all data-free enums with an explicit repr attribute.
pub unsafe trait AsRepr: Sized {
type Repr;
fn as_repr(&self) -> Self::Repr;
}
pub unsafe trait FromRepr: AsRepr {
fn try_from_repr(from: Self::Repr) -> Result<Self, TryFromReprError<Self::Repr>>;
unsafe fn from_repr(from: Self::Repr) -> Self;
}
Steps / History
Unresolved Questions
- Do we want a blanket impl of
FromRepr for Discriminant<T>? We want to consider carefully if that impl would have unwanted semver implications.
Feature gate:
#![feature(enum_as_repr)]This is a tracking issue for traits to convert primitive enums into their repr (
core::enums::AsRepr), and attempt to convert reprs into primitive enums (core::enums::FromRepr).AsRepris automatically implemented for all relevant enum types, as well asstd::mem::Discriminant, andFromReprmay be derived.Public API
Steps / History
Unresolved Questions
FromReprforDiscriminant<T>? We want to consider carefully if that impl would have unwanted semver implications.