pub struct Ptr<'a, T: 'a> { /* private fields */ }
Expand description
A thread-safe pointer wrapper for shared mutable access.
Ptr provides a way to safely share mutable references across threads using atomic operations.
It wraps an AtomicPtr
and provides methods to access the underlying data safely.
§Type Parameters
'a
- Lifetime parameter for the referenceT
- Type of the data being pointed to
§Safety
This type uses unsafe operations internally but provides a safe interface.
The caller must ensure that the pointer remains valid for the lifetime 'a
.
§Example
use plux_rs::utils::Ptr;
let mut data = 42;
let ptr = Ptr::new(&mut data);
// Access as immutable reference
let value = ptr.as_ref();
assert_eq!(*value, 42);
// Access as mutable reference
let mut_ref = ptr.as_mut();
*mut_ref = 24;
assert_eq!(*ptr.as_ref(), 24);
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> !Freeze for Ptr<'a, T>
impl<'a, T> RefUnwindSafe for Ptr<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for Ptr<'a, T>where
T: Sync,
impl<'a, T> Sync for Ptr<'a, T>where
T: Sync,
impl<'a, T> Unpin for Ptr<'a, T>
impl<'a, T> UnwindSafe for Ptr<'a, 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more