offset_of_slice

The tracking issue for this feature is: #120141


When the offset_of_enum feature is enabled, the offset_of! macro may be used to obtain the offsets of fields of enums; to express this, enum variants may be traversed as if they were fields. Variants themselves do not have an offset, so they cannot appear as the last path component.

#![allow(unused)] #![feature(offset_of_enum)] fn main() { use std::mem; #[repr(u8)] enum Enum { A(u8, u16), B { one: u8, two: u16 }, } assert_eq!(mem::offset_of!(Enum, A.0), 1); assert_eq!(mem::offset_of!(Enum, B.two), 2); assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0); }