Open
Description
Feature gate: #![feature(offset_of_enum)]
This is a tracking issue for using enum variants in offset_of. Enum variants themselves do not have an offset within their type, so the macro will not give an offset for them, but their fields do. For example, the standard library uses the offset of the content of the Some
variant of Option
to implement Option::as_slice
. The original RFC for offset_of was rust-lang/rfcs#3308.
Public API
pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) { ... }
const OFFSET: usize = offset_of!(Option<u32>, Some.0);
Steps / History
- Implementation: Support enum variants in offset_of! #114208
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should the syntax for enum variants differ from the syntax for field names in offset_of? https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/.60offset_of!.60.20Syntax/
Footnotes
Metadata
Metadata
Assignees
Labels
Category: An issue tracking the progress of sth. like the implementation of an RFC`#![feature(offset_of_enum)]`Items that are on lang's radar and will need eventual work or consideration.Relevant to the language team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.