Skip to content

Commit 5f90525

Browse files
committed
Add comment about addr_of_mut!()
1 parent e1f8d18 commit 5f90525

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ impl<T> RingBuffer<T> {
152152
let ptr: *mut [T] = core::ptr::slice_from_raw_parts_mut(ptr.cast(), capacity);
153153
// ... and coerce it into our own dynamically sized type:
154154
let ptr = ptr as *mut Self;
155+
156+
// Since Rust 1.51 addr_of_mut!((*ptr).$field_name).write(...) can be used
157+
// to get a properly typed (and aligned) pointer for field initialization
158+
// (instead of manually casting from `*mut u8`).
159+
155160
// Safety: Null check has been done above
156161
NonNull::new_unchecked(ptr)
157162
};

0 commit comments

Comments
 (0)