Offset from (#705)

This commit is contained in:
Brad Dunbar
2024-05-11 19:41:50 +02:00
committed by GitHub
parent 86694b0564
commit 4950c50376
3 changed files with 20 additions and 39 deletions
+15
View File
@@ -148,3 +148,18 @@ fn panic_does_not_fit(size: usize, nbytes: usize) -> ! {
size, nbytes
);
}
/// Precondition: dst >= original
///
/// The following line is equivalent to:
///
/// ```rust,ignore
/// self.ptr.as_ptr().offset_from(ptr) as usize;
/// ```
///
/// But due to min rust is 1.39 and it is only stabilized
/// in 1.47, we cannot use it.
#[inline]
fn offset_from(dst: *const u8, original: *const u8) -> usize {
dst as usize - original as usize
}