aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorGravatar Brad Dunbar <dunbarb2@gmail.com> 2024-05-11 13:41:50 -0400
committerGravatar GitHub <noreply@github.com> 2024-05-11 19:41:50 +0200
commit4950c503768fcebce6f9ab9dbaac2a7da30b35ba (patch)
treee57830fa89151939757400ece1fb070087eb8558 /src/lib.rs
parent86694b05649c0c1666044b2ba5c386c2328aac18 (diff)
downloadbytes-4950c503768fcebce6f9ab9dbaac2a7da30b35ba.tar.gz
bytes-4950c503768fcebce6f9ab9dbaac2a7da30b35ba.tar.zst
bytes-4950c503768fcebce6f9ab9dbaac2a7da30b35ba.zip
Offset from (#705)
Diffstat (limited to '')
-rw-r--r--src/lib.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 4dd1180..7ddd220 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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
+}