gep
gep, a better pointer arithmetic library.
The name gep comes from LLVM's getelementptr instruction, the infamous
pointer arithmetic operation.
This library provides two new pointer types, [Ptr] and [NonNull], which
have very similar APIs; they correspond to *mut T and
[core::ptr::NonNull], respectively.
It also provides Rusty versions of [memcpy], [memmove], and [memset].
Offsets
The premiere operation provided by this library is [Ptr::at()], which is
a generalized pointer arithmetic operation. For example, it will accept
any integer as input, not just isize (although, like [<*mut T>::offset],
the offset value must be valid to convert to isize).
let mut ints = ;
let p = from.element;
unsafe
assert_eq!;
By default, at() works on multiples of elements. To do a direct byte
offset instead, you can use the [offset::ByteOffset] type instead.
use ByteOffset;
let mut ints = ;
let p = from.element;
unsafe
assert_eq!;
It's also possible to use "field offsets" (via the [offset::Field] type)
for accessing the fields of a struct directly, without creating intermediate
references to potentially invalid data.
use Field;
let foo = Foo ;
let p = from;
let value = unsafe ;
assert_eq!;
License: Apache-2.0