Trait std::ptr::PtrExtStable [-]  [+] [src]

pub trait PtrExt {
    type Target;
    fn is_null(self) -> bool;
    unsafe fn as_ref(&self) -> Option<&'a <Self as PtrExt>::Target>;
    unsafe fn offset(self, count: isize) -> Self;
}

Methods on raw pointers

Required Methods

type Target

fn is_null(self) -> bool

Returns true if the pointer is null.

unsafe fn as_ref(&self) -> Option<&'a <Self as PtrExt>::Target>

Returns None if the pointer is null, or else returns a reference to the value wrapped in Some.

Safety

While this method and its mutable counterpart are useful for null-safety, it is important to note that this is still an unsafe operation because the returned value could be pointing to invalid memory.

unsafe fn offset(self, count: isize) -> Self

Calculates the offset from a pointer. count is in units of T; e.g. a count of 3 represents a pointer offset of 3 * sizeof::<T>() bytes.

Safety

The offset must be in-bounds of the object, or one-byte-past-the-end. Otherwise offset invokes Undefined Behaviour, regardless of whether the pointer is used.

Implementors