[−][src]Trait rel_ptr::Delta
Delta
trait generalizes differences in
memory locations to types like i8 and i16
Note: certain invariants must be upheld to fulfill the unsafe contract of this trait, these invariants are detailed in each function
This trait is intended to be used with RelPtr
Associated Types
type Error
Error of Delta::sub
Associated Constants
const ZERO: Self
The value No change in two pointer locations,
Required methods
fn sub(a: *const u8, b: *const u8) -> Result<Self, Self::Error>
The difference between two pointers
Note: for all values of a: *const u8
,
you must enforce that Delta::sub(a, a) == Delta::ZERO
and that the following function does not panic for all values
of a
and b
fn for_all_a_b(a: *const u8, b: *const u8) { if let Some(x) = Self::sub(a, b) { unsafe { assert_eq!(Self::add(x, b), a) } } }
unsafe fn sub_unchecked(a: *const u8, b: *const u8) -> Self
The difference between two pointers
Note: for all values of a: *const u8
,
you must enforce that Delta::sub(a, a) == Delta::ZERO
and that the following function does not panic for all values
of a
and b
if the difference between a
and b
is valid
fn for_all_a_b(a: *const u8, b: *const u8) { unsafe { assert_eq!(Self::add(Self::sub_unchecked(a, b), b), a) } }
Safety:
If the difference between a
and b
is not
representable by Self
is UB
unsafe fn add(self, a: *const u8) -> *mut u8
Adds the difference (in self
) to the pointer a
Note: for all values of a: *const u8
,
you must enforce that Delta::add(Delta::ZERO, a) == a
and that the following function does not panic for all values
of a
and b
fn for_all_a_b(a: *const u8, b: *const u8) { if let Some(x) = Self::sub(a, b) { unsafe { assert_eq!(Self::add(x, b), a) } } }
Safety
TODO