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: Copy> Copy for Pointer<T>
impl<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Return a random value via the
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
👎Deprecated since 0.9.0: Renamed to
random to avoid conflict with the new gen keyword in Rust 2024.Alias for
Rng::random.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
👎Deprecated since 0.9.0: Renamed to
random_rangeAlias for
Rng::random_range.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
The type returned in the event of a RNG error.
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
Return the next random
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
Return the next random
u64.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
Fill
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
Wrap RNG with the
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
Convert an
RngCore to a RngReadAdapter.