diff --git a/src/ring_buffer/mod.rs b/src/ring_buffer/mod.rs index 199e82e5022f9b72957c13dbf342355cadd3acf8..5647f77bdcfa789279ccfee4529ce68d8515a7a0 100644 --- a/src/ring_buffer/mod.rs +++ b/src/ring_buffer/mod.rs @@ -48,7 +48,7 @@ where let buffer: &[T] = unsafe { self.buffer.as_ref() }; if self.head != self.tail { - let item = unsafe { ptr::read(&buffer[self.head]) }; + let item = unsafe { ptr::read(buffer.as_ptr().offset(self.head as isize)) }; self.head = (self.head + 1) % n; Some(item) } else { @@ -64,7 +64,7 @@ where if next_tail != self.head { // NOTE(ptr::write) the memory slot that we are about to write to is uninitialized. We // use `ptr::write` to avoid running `T`'s destructor on the uninitialized memory - unsafe { ptr::write(&mut buffer[self.tail], item) } + unsafe { ptr::write(buffer.as_mut_ptr().offset(self.tail as isize), item) } self.tail = next_tail; Ok(()) } else { diff --git a/src/ring_buffer/spsc.rs b/src/ring_buffer/spsc.rs index f12f48dc700fcd16bd4d1b4d188069874b2544ea..dc6d0f53479888d4fe2cbb28b65a3bd809e2d747 100644 --- a/src/ring_buffer/spsc.rs +++ b/src/ring_buffer/spsc.rs @@ -43,7 +43,7 @@ where // NOTE(volatile) the value of `tail` can change at any time in the context of the consumer // so we inform this to the compiler using a volatile load if rb.head != unsafe { ptr::read_volatile(&rb.tail) } { - let item = unsafe { ptr::read(&buffer[rb.head]) }; + let item = unsafe { ptr::read(buffer.as_ptr().offset(rb.head as isize)) }; rb.head = (rb.head + 1) % n; Some(item) } else { @@ -78,7 +78,7 @@ where if next_tail != unsafe { ptr::read_volatile(&rb.head) } { // NOTE(ptr::write) the memory slot that we are about to write to is uninitialized. We // use `ptr::write` to avoid running `T`'s destructor on the uninitialized memory - unsafe { ptr::write(&mut buffer[rb.tail], item) } + unsafe { ptr::write(buffer.as_mut_ptr().offset(rb.tail as isize), item) } rb.tail = next_tail; Ok(()) } else {