rawpointer 0.2.1

Extra methods for raw pointers and `NonNull<T>`. For example `.post_inc()` and `.pre_dec()` (c.f. `ptr++` and `--ptr`), `offset` and `add` for `NonNull<T>`, and the function `ptrdistance`.
Documentation
  • Coverage
  • 76.92%
    10 out of 13 items documented1 out of 13 items with examples
  • Size
  • Source code size: 20.61 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 736.63 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • bluss/rawpointer
    4 2 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bluss jturner314

Rawpointer adds extra utility methods to raw pointers *const T, *mut T and NonNull<T>.

Features include:

  • Strided offsets - .stride_offset(stride, index) make it easy to compute pointer offsets where the index is unsigned and the stride is signed.

  • Offsetting methods in general for NonNull, since it does not have these from libcore

  • Post- and preincrement and post- and predecrement methods

use rawpointer::PointerExt;

unsafe {
    // In this example:
    // Use .post_inc() to iterate and overwrite the first four
    // elements of the array.

    let mut xs = [0; 16];
    let mut ptr = xs.as_mut_ptr();
    let end = ptr.offset(4);
    let mut i = 0;
    while ptr != end {
        *ptr.post_inc() = i;
        i += 1;
    }
    assert_eq!(&xs[..8], &[0, 1, 2, 3, 0, 0, 0, 0]);
}

Safety

See the Rust [core::ptr] documentation for more information.

Rust Version

This version of the crate requires Rust 1.26 or later