Skip to content

Commit 191c06c

Browse files
authored
Remove useless unsafe, mut and ptr casts in example in send-and-sync.md (#308)
1 parent 2747c4b commit 191c06c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/send-and-sync.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<T> Carton<T> {
102102
pub fn new(value: T) -> Self {
103103
// Allocate enough memory on the heap to store one T.
104104
assert_ne!(size_of::<T>(), 0, "Zero-sized types are out of the scope of this example");
105-
let mut memptr = ptr::null_mut() as *mut T;
105+
let mut memptr: *mut T = ptr::null_mut();
106106
unsafe {
107107
let ret = libc::posix_memalign(
108108
(&mut memptr).cast(),
@@ -113,10 +113,10 @@ impl<T> Carton<T> {
113113
};
114114

115115
// NonNull is just a wrapper that enforces that the pointer isn't null.
116-
let mut ptr = unsafe {
116+
let ptr = {
117117
// Safety: memptr is dereferenceable because we created it from a
118118
// reference and have exclusive access.
119-
ptr::NonNull::new(memptr.cast::<T>())
119+
ptr::NonNull::new(memptr)
120120
.expect("Guaranteed non-null if posix_memalign returns 0")
121121
};
122122

0 commit comments

Comments
 (0)