@@ -1256,10 +1256,6 @@ impl<T> SizedTypeProperties for T {}
1256
1256
///
1257
1257
/// The offset is returned as a [`usize`].
1258
1258
///
1259
- /// If the nightly-only feature `offset_of_enum` is enabled,
1260
- /// `enum` variants may be traversed as if they were fields.
1261
- /// Variants themselves do not have an offset.
1262
- ///
1263
1259
/// # Offsets of, and in, dynamically sized types
1264
1260
///
1265
1261
/// The field’s type must be [`Sized`], but it may be located in a [dynamically sized] container.
@@ -1338,11 +1334,16 @@ impl<T> SizedTypeProperties for T {}
1338
1334
///
1339
1335
/// [explicit `repr` attribute]: https://doc.rust-lang.org/reference/type-layout.html#representations
1340
1336
///
1337
+ /// # Unstable features
1338
+ ///
1339
+ /// The following unstable features expand the functionality of `offset_of!`:
1340
+ ///
1341
+ /// * [`offset_of_enum`] — allows `enum` variants to be traversed as if they were fields.
1342
+ /// * [`offset_of_slice`] — allows getting the offset of a field of type `[T]`.
1343
+ ///
1341
1344
/// # Examples
1342
1345
///
1343
1346
/// ```
1344
- /// #![feature(offset_of_enum)]
1345
- ///
1346
1347
/// use std::mem;
1347
1348
/// #[repr(C)]
1348
1349
/// struct FieldStruct {
@@ -1364,20 +1365,11 @@ impl<T> SizedTypeProperties for T {}
1364
1365
/// struct NestedB(u8);
1365
1366
///
1366
1367
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
1367
- ///
1368
- /// #[repr(u8)]
1369
- /// enum Enum {
1370
- /// A(u8, u16),
1371
- /// B { one: u8, two: u16 },
1372
- /// }
1373
- ///
1374
- /// assert_eq!(mem::offset_of!(Enum, A.0), 1);
1375
- /// assert_eq!(mem::offset_of!(Enum, B.two), 2);
1376
- ///
1377
- /// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
1378
1368
/// ```
1379
1369
///
1380
1370
/// [dynamically sized]: https://doc.rust-lang.org/reference/dynamically-sized-types.html
1371
+ /// [`offset_of_enum`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-enum.html
1372
+ /// [`offset_of_slice`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-slice.html
1381
1373
#[ stable( feature = "offset_of" , since = "1.77.0" ) ]
1382
1374
#[ allow_internal_unstable( builtin_syntax) ]
1383
1375
pub macro offset_of ( $Container: ty, $( $fields: expr) + $( , ) ?) {
0 commit comments