Skip to content

Commit

Permalink
Add comment about addr_of_mut!()
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Jun 11, 2022
1 parent f9e9945 commit 7b5e607
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ impl<T> RingBuffer<T> {
let ptr: *mut [T] = core::ptr::slice_from_raw_parts_mut(ptr.cast(), capacity);
// ... and coerce it into our own dynamically sized type:
let ptr = ptr as *mut Self;

// Since Rust 1.51 addr_of_mut!((*ptr).$field_name).write(...) can be used
// to get a properly typed (and aligned) pointer for field initialization
// (instead of manually casting from `*mut u8`).

// Safety: Null check has been done above
NonNull::new_unchecked(ptr)
};
Expand Down

0 comments on commit 7b5e607

Please sign in to comment.