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 May 22, 2022
1 parent db8d35f commit dcae2aa
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 dcae2aa

Please sign in to comment.