diff options
author | 2024-05-11 13:41:50 -0400 | |
---|---|---|
committer | 2024-05-11 19:41:50 +0200 | |
commit | 4950c503768fcebce6f9ab9dbaac2a7da30b35ba (patch) | |
tree | e57830fa89151939757400ece1fb070087eb8558 /src/lib.rs | |
parent | 86694b05649c0c1666044b2ba5c386c2328aac18 (diff) | |
download | bytes-4950c503768fcebce6f9ab9dbaac2a7da30b35ba.tar.gz bytes-4950c503768fcebce6f9ab9dbaac2a7da30b35ba.tar.zst bytes-4950c503768fcebce6f9ab9dbaac2a7da30b35ba.zip |
Offset from (#705)
Diffstat (limited to '')
-rw-r--r-- | src/lib.rs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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 +} |