Calculate distance between two raw pointers
Since 1.47.0 (October 2020), Rust has the offset_from
method on the pointer type, allowing you to write:
let offset: isize = end.offset_from(start);
to get the offset from start
to end
.
A raw pointer can be cast to usize
; you can then perform subtraction on those.
end as usize - start as usize