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

pub trait PtrExt<T> {
    fn null() -> Self;
    fn is_null(self) -> bool;
    fn to_uint(self) -> uint;
    unsafe fn as_ref<'a>(&self) -> Option<&'a T>;
    unsafe fn offset(self, count: int) -> Self;

    fn is_not_null(self) -> bool { ... }
}

Methods on raw pointers

Required Methods

fn null() -> Self

Returns the null pointer.

fn is_null(self) -> bool

Returns true if the pointer is null.

fn to_uint(self) -> uint

Returns true if the pointer is not null.

unsafe fn as_ref<'a>(&self) -> Option<&'a T>

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: int) -> 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.

Provided Methods

fn is_not_null(self) -> bool

Returns true if the pointer is not equal to the null pointer.

Implementors