pub struct Ptr<'g, T> { /* private fields */ }Expand description
Ptr points to an instance.
Implementations§
Source§impl<'g, T> Ptr<'g, T>
impl<'g, T> Ptr<'g, T>
Sourcepub fn as_ref(&self) -> Option<&'g T>
pub fn as_ref(&self) -> Option<&'g T>
Tries to create a reference to the underlying instance.
§Examples
use sdd::{AtomicShared, Guard};
use std::sync::atomic::Ordering::Relaxed;
let atomic_shared: AtomicShared<usize> = AtomicShared::new(21);
let guard = Guard::new();
let ptr = atomic_shared.load(Relaxed, &guard);
assert_eq!(*ptr.as_ref().unwrap(), 21);Sourcepub const unsafe fn as_ref_unchecked(&self) -> Option<&'g T>
pub const unsafe fn as_ref_unchecked(&self) -> Option<&'g T>
Tries to create a reference to the underlying instance without checking tag bits.
§Safety
This Ptr must not have any tag bits set, otherwise dereferencing the pointer may lead to
undefined behavior.
§Examples
use sdd::{AtomicShared, Guard};
use std::sync::atomic::Ordering::Relaxed;
let atomic_shared: AtomicShared<usize> = AtomicShared::new(21);
let guard = Guard::new();
let ptr = atomic_shared.load(Relaxed, &guard);
assert_eq!(unsafe { *ptr.as_ref_unchecked().unwrap() }, 21);Sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Provides a raw pointer to the instance.
§Examples
use sdd::{Guard, Shared};
use std::sync::atomic::Ordering::Relaxed;
let shared: Shared<usize> = Shared::new(29);
let guard = Guard::new();
let ptr = shared.get_guarded_ptr(&guard);
drop(shared);
assert_eq!(unsafe { *ptr.as_ptr() }, 29);Sourcepub const unsafe fn as_ptr_unchecked(&self) -> *const T
pub const unsafe fn as_ptr_unchecked(&self) -> *const T
Tries to create a pointer to the underlying instance without checking tag bits.
§Safety
This Ptr must not have any tag bits set, otherwise dereferencing the pointer may lead to
undefined behavior.
§Examples
use sdd::{AtomicShared, Guard};
use std::sync::atomic::Ordering::Relaxed;
let atomic_shared: AtomicShared<usize> = AtomicShared::new(21);
let guard = Guard::new();
let ptr = atomic_shared.load(Relaxed, &guard);
assert_eq!(unsafe { *ptr.as_ptr_unchecked() }, 21);Sourcepub fn without_tag(self) -> Self
pub fn without_tag(self) -> Self
Tries to convert itself into a Shared.
§Examples
use sdd::{Guard, Shared};
let shared: Shared<usize> = Shared::new(83);
let guard = Guard::new();
let ptr = shared.get_guarded_ptr(&guard);
let shared_restored = ptr.get_shared().unwrap();
assert_eq!(*shared_restored, 83);
drop(shared);
drop(shared_restored);
assert!(ptr.get_shared().is_none());Trait Implementations§
impl<T> Copy for Ptr<'_, T>
impl<T> Eq for Ptr<'_, T>
impl<T: UnwindSafe> UnwindSafe for Ptr<'_, T>
Auto Trait Implementations§
impl<'g, T> Freeze for Ptr<'g, T>
impl<'g, T> RefUnwindSafe for Ptr<'g, T>where
T: RefUnwindSafe,
impl<'g, T> !Send for Ptr<'g, T>
impl<'g, T> !Sync for Ptr<'g, T>
impl<'g, T> Unpin for Ptr<'g, T>
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