pub trait PointerExt : Copy {
unsafe fn offset(self, i: isize) -> Self;
#[inline(always)]
unsafe fn inc(&mut self) {
*self = self.offset(1);
}
#[inline(always)]
unsafe fn post_inc(&mut self) -> Self {
let current = *self;
*self = self.offset(1);
current
}
#[inline(always)]
unsafe fn dec(&mut self) {
*self = self.offset(-1);
}
#[inline(always)]
unsafe fn pre_dec(&mut self) -> Self {
*self = self.offset(-1);
*self
}
#[inline(always)]
unsafe fn stride_offset(self, s: isize, index: usize) -> Self {
self.offset(s * index as isize)
}
}
impl<T> PointerExt for *const T {
#[inline(always)]
unsafe fn offset(self, i: isize) -> Self {
self.offset(i)
}
}
impl<T> PointerExt for *mut T {
#[inline(always)]
unsafe fn offset(self, i: isize) -> Self {
self.offset(i)
}
}