Stable method to calculate the distance between two raw pointers

Both of offset_from and wrapping_offset_from need feature ( ptr_offset_from or ptr_wrapping_offset_from), but I want to calculate the distance between two raw pointers in stable Rust, how can I do this trick?

Also I read the github issue from https://github.com/rust-lang/rust/issues/41079, when will these methods be stable?

You should be able to cast the pointers to integers and do arithmetic there. That'll be in bytes, versus type-sized units for those methods.

1 Like