sdd

Struct 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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>

Source§

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§

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

🔬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,

Source§

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>,

Source§

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>,

Source§

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.