Function abi_stable::utils::distance_from

source ·
pub fn distance_from<T>(from: *const T, to: *const T) -> Option<usize>
Expand description

This function allows calculating the distance (in Ts) from from to to.

This returns None if from has a higher address than to, or if T is a zero sized type.

§Example

use abi_stable::utils;

let arr = ["hello", "world", "foo", "bar", "baz"];

assert_eq!(utils::distance_from(&arr[0], &arr[0]), Some(0));
assert_eq!(utils::distance_from(&arr[0], &arr[4]), Some(4));

assert_eq!(utils::distance_from(&arr[4], &arr[0]), None);