d8a3fc4d71
Add convenience byte offset/check align functions to pointers This PR adds the following APIs: ```rust impl *const T { // feature gates `pointer_byte_offsets` and `const_pointer_byte_offsets pub const unsafe fn byte_offset(self, count: isize) -> Self; pub const fn wrapping_byte_offset(self, count: isize) -> Self; pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize; 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_add(self, count: usize) -> Self; pub const fn wrapping_byte_sub(self, count: usize) -> Self; // feature gate `pointer_is_aligned` pub fn is_aligned(self) -> bool where T: Sized; pub fn is_aligned_to(self, align: usize) -> bool; } // ... and the same for` *mut T` ``` Note that all functions except `is_aligned` do **not** require `T: Sized` as their pointee-sized-offset counterparts. cc `@oli-obk` (you may want to check that I've correctly placed `const`s) cc `@RalfJung` |
||
---|---|---|
.. | ||
benches | ||
primitive_docs | ||
src | ||
tests | ||
Cargo.toml |