Struct sdd::Ptr

source ·
pub struct Ptr<'g, T> { /* private fields */ }
Expand description

Ptr points to an instance.

Implementations§

source§

impl<'g, T> Ptr<'g, T>

source

pub const fn null() -> Self

Creates a null Ptr.

§Examples
use sdd::Ptr;

let ptr: Ptr<usize> = Ptr::null();
source

pub fn is_null(&self) -> bool

Returns true if the Ptr is null.

§Examples
use sdd::Ptr;

let ptr: Ptr<usize> = Ptr::null();
assert!(ptr.is_null());
source

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);
source

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);
source

pub fn tag(&self) -> Tag

Returns its Tag.

§Examples
use sdd::{Ptr, Tag};

let ptr: Ptr<usize> = Ptr::null();
assert_eq!(ptr.tag(), Tag::None);
source

pub fn set_tag(&mut self, tag: Tag) -> Tag

Sets a Tag, overwriting its existing Tag.

Returns the previous tag value.

§Examples
use sdd::{Ptr, Tag};

let mut ptr: Ptr<usize> = Ptr::null();
assert_eq!(ptr.set_tag(Tag::Both), Tag::None);
assert_eq!(ptr.tag(), Tag::Both);
source

pub fn unset_tag(&mut self) -> Tag

Clears its Tag.

Returns the previous tag value.

§Examples
use sdd::{Ptr, Tag};

let mut ptr: Ptr<usize> = Ptr::null().with_tag(Tag::Both);
assert_eq!(ptr.unset_tag(), Tag::Both);
source

pub fn with_tag(self, tag: Tag) -> Self

Returns a copy of self with a Tag set.

§Examples
use sdd::{Ptr, Tag};

let mut ptr: Ptr<usize> = Ptr::null();
assert_eq!(ptr.tag(), Tag::None);

let ptr_with_tag = ptr.with_tag(Tag::First);
assert_eq!(ptr_with_tag.tag(), Tag::First);
source

pub fn without_tag(self) -> Self

Returns a copy of self with its Tag erased.

§Examples
use sdd::{Ptr, Tag};

let mut ptr: Ptr<usize> = Ptr::null();
ptr.set_tag(Tag::Second);
assert_eq!(ptr.tag(), Tag::Second);

let ptr_without_tag = ptr.without_tag();
assert_eq!(ptr_without_tag.tag(), Tag::None);
source

pub fn get_shared(self) -> Option<Shared<T>>

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§

source§

impl<'g, T> Clone for Ptr<'g, T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'g, T: Debug> Debug for Ptr<'g, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'g, T> Default for Ptr<'g, T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'g, T> PartialEq for Ptr<'g, T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'g, T> TryFrom<Ptr<'g, T>> for Shared<T>

§

type Error = Ptr<'g, T>

The type returned in the event of a conversion error.
source§

fn try_from(ptr: Ptr<'g, T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'g, T> Copy for Ptr<'g, T>

source§

impl<'g, T> Eq for Ptr<'g, T>

source§

impl<'g, T: UnwindSafe> UnwindSafe for Ptr<'g, 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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.