W3cubDocs

/Rust

Function offset_of

pub const fn offset_of<T>(variant: u32, field: u32) -> usizewhere
    T: ?Sized,
🔬This is a nightly-only experimental API. (core_intrinsics)

The offset of a field inside a type.

Note that, unlike most intrinsics, this is safe to call; it does not require an unsafe block. Therefore, implementations must not require the user to uphold any safety invariants.

This intrinsic can only be evaluated at compile-time, and should only appear in constants or inline const blocks.

The stabilized version of this intrinsic is core::mem::offset_of. This intrinsic is also a lang item so offset_of! can desugar to calls to it.

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/intrinsics/fn.offset_of.html