Skip to content

Tracking Issue for enum_as_repr #86772

Closed
Closed
@illicitonion

Description

@illicitonion

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions