Closed
Description
openedon Apr 21, 2022
Feature gates:
#![feature(pointer_byte_offsets)]
#![feature(const_pointer_byte_offsets)]
This is a tracking issue for the pointer_byte_offsets raw pointer conveniences like ptr.byte_add(offset)
Public API
impl<T: ?Sized> *const T {
// feature gates `pointer_byte_offsets` and `const_pointer_byte_offsets`
pub const unsafe fn byte_offset(self, count: isize) -> Self;
pub const unsafe fn byte_add(self, count: usize) -> Self;
pub const unsafe fn byte_sub(self, count: usize) -> Self;
pub const fn wrapping_byte_offset(self, count: isize) -> Self;
pub const fn wrapping_byte_add(self, count: usize) -> Self;
pub const fn wrapping_byte_sub(self, count: usize) -> Self;
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize;
}
// ... and the same for` *mut T`
Steps / History
- Implementation: Add convenience byte offset/check align functions to pointers #95643
- Making
byte_offset_from
more generic: Makepointer::byte_offset_from
more generic #103489 - Final comment period (FCP): Tracking Issue for pointer_bytes_offsets #96283 (comment)
- Stabilization PR: Stabilize
[const_]pointer_byte_offsets
#116205
Unresolved Questions
- Should these operations actually accomodate DSTs? This seems deeply semantically dubious/broken but idk, you can plausibly use them right if you are extremely careful and understand the implications of stacked borrows for slices/projections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment