[][src]Trait rel_ptr::Delta

pub unsafe trait Delta: Copy + Eq {
    type Error;

    const ZERO: Self;

    fn sub(a: *const u8, b: *const u8) -> Result<Self, Self::Error>;
unsafe fn add(self, a: *const u8) -> *mut u8; }

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

Loading content...

Associated Constants

const ZERO: Self

The value No change in two pointer locations,

Loading content...

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

This example is not tested
 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 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

This example is not tested
 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

Loading content...

Implementations on Foreign Types

impl Delta for i8[src]

type Error = IntegerDeltaError

impl Delta for i16[src]

type Error = IntegerDeltaError

impl Delta for i32[src]

type Error = IntegerDeltaError

impl Delta for i64[src]

type Error = IntegerDeltaError

impl Delta for i128[src]

type Error = IntegerDeltaError

impl Delta for isize[src]

type Error = IntegerDeltaError

Loading content...

Implementors

Loading content...