Trait memchr::ext::Pointer

source ·
pub(crate) trait Pointer {
    // Required methods
    unsafe fn distance(self, origin: Self) -> usize;
    fn as_usize(self) -> usize;
}
Expand description

A trait for adding some helper routines to pointers.

Required Methods§

source

unsafe fn distance(self, origin: Self) -> usize

Returns the distance, in units of T, between self and origin.

§Safety

Same as ptr::offset_from in addition to self >= origin.

source

fn as_usize(self) -> usize

Casts this pointer to usize.

Callers should not convert the usize back to a pointer if at all possible. (And if you believe it’s necessary, open an issue to discuss why. Otherwise, it has the potential to violate pointer provenance.) The purpose of this function is just to be able to do arithmetic, i.e., computing offsets or alignments.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> Pointer for *const T

source§

unsafe fn distance(self, origin: *const T) -> usize

source§

fn as_usize(self) -> usize

source§

impl<T> Pointer for *mut T

source§

unsafe fn distance(self, origin: *mut T) -> usize

source§

fn as_usize(self) -> usize

Implementors§