rawpointer

Trait PointerExt

Source
pub trait PointerExt: Copy {
    // Required method
    unsafe fn offset(self, i: isize) -> Self;

    // Provided methods
    unsafe fn add(self, i: usize) -> Self { ... }
    unsafe fn sub(self, i: usize) -> Self { ... }
    unsafe fn pre_inc(&mut self) -> Self { ... }
    unsafe fn post_inc(&mut self) -> Self { ... }
    unsafe fn pre_dec(&mut self) -> Self { ... }
    unsafe fn post_dec(&mut self) -> Self { ... }
    unsafe fn inc(&mut self) { ... }
    unsafe fn dec(&mut self) { ... }
    unsafe fn stride_offset(self, s: isize, index: usize) -> Self { ... }
}
Expand description

Extension methods for raw pointers

Required Methods§

Source

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

Provided Methods§

Source

unsafe fn add(self, i: usize) -> Self

Source

unsafe fn sub(self, i: usize) -> Self

Source

unsafe fn pre_inc(&mut self) -> Self

Increment the pointer by 1, and return its new value.

Equivalent to the C idiom ++ptr.

Source

unsafe fn post_inc(&mut self) -> Self

Increment the pointer by 1, but return its old value.

Equivalent to the C idiom ptr++.

Source

unsafe fn pre_dec(&mut self) -> Self

Decrement the pointer by 1, and return its new value.

Equivalent to the C idiom --ptr.

Source

unsafe fn post_dec(&mut self) -> Self

Decrement the pointer by 1, but return its old value.

Equivalent to the C idiom ptr--.

Source

unsafe fn inc(&mut self)

Increment by 1

Source

unsafe fn dec(&mut self)

Decrement by 1

Source

unsafe fn stride_offset(self, s: isize, index: usize) -> Self

Offset the pointer by s multiplied by index.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> PointerExt for *const T

Source§

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

Source§

unsafe fn add(self, i: usize) -> Self

Source§

unsafe fn sub(self, i: usize) -> Self

Source§

impl<T> PointerExt for *mut T

Source§

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

Source§

unsafe fn add(self, i: usize) -> Self

Source§

unsafe fn sub(self, i: usize) -> Self

Source§

impl<T> PointerExt for NonNull<T>

NonNull<T> supports the same offsetting methods under the same safety constraints as the other raw pointer implementations.

There is no difference - both when offsetting *mut T and NonNull<T>, the offset is only well defined if we remain inside the same object or one-past the end, and we can never land in a null pointer while obeying those rules.

Source§

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

Implementors§