pub struct Pointer<T> {
pub ptr: *mut T,
}Expand description
Pointer wrapper struct for raw pointers This is for wrapping raw pointers to make them safe for multithreading
This is for internal use only
Fields§
§ptr: *mut Traw pointer
Implementations§
Source§impl<T> Pointer<T>
impl<T> Pointer<T>
Sourcepub fn modify(&mut self, offset: i64, value: T)
pub fn modify(&mut self, offset: i64, value: T)
modify the value of the pointer in the address by the specified offset
§Arguments
offset - the offset from the current address
value - the value to be written
§Example
use tensor_pointer::Pointer;
let mut _a = unsafe { std::alloc::alloc(std::alloc::Layout::new::<i32>()) as *mut i32 };
let mut a = Pointer::<i32>::new(_a);
a.modify(0, 10);
assert_eq!(a.read(), 10);
unsafe { std::alloc::dealloc(_a as *mut u8, std::alloc::Layout::new::<i32>()); }Sourcepub fn add(&mut self, offset: usize)
pub fn add(&mut self, offset: usize)
inplace increment the value of the pointer in the current address
§Arguments
value - the value to be added
§Example
use tensor_pointer::Pointer;
let mut _a = unsafe { std::alloc::alloc(std::alloc::Layout::new::<i32>()) as *mut i32 };
unsafe { _a.write(10); }
let mut a = Pointer::<i32>::new(_a);
a.add(0);
assert_eq!(a.read(), 10);
unsafe { std::alloc::dealloc(_a as *mut u8, std::alloc::Layout::new::<i32>()); }Sourcepub fn offset(&mut self, offset: i64)
pub fn offset(&mut self, offset: i64)
inplace offset the value of the pointer in the current address
§Arguments
offset - the offset to be added
§Example
use tensor_pointer::Pointer;
let mut _a = unsafe { std::alloc::alloc(std::alloc::Layout::new::<i32>()) as *mut i32 };
unsafe { _a.write(10); }
let mut a = Pointer::<i32>::new(_a);
a.offset(0);
assert_eq!(a.read(), 10);
unsafe { std::alloc::dealloc(_a as *mut u8, std::alloc::Layout::new::<i32>()); }Trait Implementations§
Source§impl<T> AddAssign<i64> for &mut Pointer<T>
impl<T> AddAssign<i64> for &mut Pointer<T>
Source§fn add_assign(&mut self, rhs: i64)
fn add_assign(&mut self, rhs: i64)
Performs the
+= operation. Read moreSource§impl<T> AddAssign<i64> for Pointer<T>
impl<T> AddAssign<i64> for Pointer<T>
Source§fn add_assign(&mut self, rhs: i64)
fn add_assign(&mut self, rhs: i64)
Performs the
+= operation. Read moreSource§impl<T> AddAssign<isize> for Pointer<T>
impl<T> AddAssign<isize> for Pointer<T>
Source§fn add_assign(&mut self, rhs: isize)
fn add_assign(&mut self, rhs: isize)
Performs the
+= operation. Read moreSource§impl<T> AddAssign<usize> for &mut Pointer<T>
impl<T> AddAssign<usize> for &mut Pointer<T>
Source§fn add_assign(&mut self, rhs: usize)
fn add_assign(&mut self, rhs: usize)
Performs the
+= operation. Read moreSource§impl<T> AddAssign<usize> for Pointer<T>
impl<T> AddAssign<usize> for Pointer<T>
Source§fn add_assign(&mut self, rhs: usize)
fn add_assign(&mut self, rhs: usize)
Performs the
+= operation. Read moreSource§impl<T> SubAssign<i64> for &mut Pointer<T>
impl<T> SubAssign<i64> for &mut Pointer<T>
Source§fn sub_assign(&mut self, rhs: i64)
fn sub_assign(&mut self, rhs: i64)
Performs the
-= operation. Read moreSource§impl<T> SubAssign<i64> for Pointer<T>
impl<T> SubAssign<i64> for Pointer<T>
Source§fn sub_assign(&mut self, rhs: i64)
fn sub_assign(&mut self, rhs: i64)
Performs the
-= operation. Read moreSource§impl<T> SubAssign<isize> for Pointer<T>
impl<T> SubAssign<isize> for Pointer<T>
Source§fn sub_assign(&mut self, rhs: isize)
fn sub_assign(&mut self, rhs: isize)
Performs the
-= operation. Read moreSource§impl<T> SubAssign<usize> for Pointer<T>
impl<T> SubAssign<usize> for Pointer<T>
Source§fn sub_assign(&mut self, rhs: usize)
fn sub_assign(&mut self, rhs: usize)
Performs the
-= operation. Read moreimpl<T> Send for Pointer<T>
impl<T> Sync for Pointer<T>
Auto Trait Implementations§
impl<T> Freeze for Pointer<T>
impl<T> RefUnwindSafe for Pointer<T>where
T: RefUnwindSafe,
impl<T> Unpin for Pointer<T>
impl<T> UnwindSafe for Pointer<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more