mirror of
https://gitee.com/openharmony/third_party_rust_memoffset
synced 2024-11-23 07:10:22 +00:00
Update docs WRT repr(Rust) (#69)
Issue: - https://github.com/Gilnaa/memoffset/issues/59
This commit is contained in:
parent
af6689589f
commit
eb2a79cb6d
@ -86,6 +86,16 @@ macro_rules! _memoffset_offset_from_unsafe {
|
||||
/// assert_eq!(offset_of!(Foo, b), 4);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ## Notes
|
||||
/// Rust's ABI is unstable, and [type layout can be changed with each
|
||||
/// compilation](https://doc.rust-lang.org/reference/type-layout.html).
|
||||
///
|
||||
/// Using `offset_of!` with a `repr(Rust)` struct will return the correct offset of the
|
||||
/// specified `field` for a particular compilation, but the exact value may change
|
||||
/// based on the compiler version, concrete struct type, time of day, or rustc's mood.
|
||||
///
|
||||
/// As a result, the value should not be retained and used between different compilations.
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! offset_of {
|
||||
($parent:path, $field:tt) => {{
|
||||
|
@ -52,11 +52,18 @@ macro_rules! _memoffset__compile_error {
|
||||
/// span_of!(Struct, start ..)
|
||||
/// ```
|
||||
///
|
||||
/// *Note*:
|
||||
/// ### Note
|
||||
/// This macro uses recursion in order to resolve the range expressions, so there is a limit to
|
||||
/// the complexity of the expression.
|
||||
/// In order to raise the limit, the compiler's recursion limit should be lifted.
|
||||
///
|
||||
/// ### Safety
|
||||
/// The inter-field form mentioned above assumes that the first field is positioned before the
|
||||
/// second.
|
||||
/// This is only guarenteed for `repr(C)` structs.
|
||||
/// Usage with `repr(Rust)` structs may yield unexpected results, like downward-going ranges,
|
||||
/// spans that include unexpected fields, empty spans, or spans that include *unexpected* padding bytes.
|
||||
///
|
||||
/// ## Examples
|
||||
/// ```
|
||||
/// use memoffset::span_of;
|
||||
|
Loading…
Reference in New Issue
Block a user