Struct scc::ebr::Ptr

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

Ptr points to an instance.

Implementations§

source§

impl<'b, T> Ptr<'b, T>

source

pub const fn null() -> Self

Creates a null Ptr.

Examples
use scc::ebr::Ptr;

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

pub fn is_null(&self) -> bool

Returns true if the Ptr is null.

Examples
use scc::ebr::Ptr;

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

pub fn as_ref(&self) -> Option<&'b T>

Tries to create a reference to the underlying instance.

Examples
use scc::ebr::{AtomicArc, Barrier};
use std::sync::atomic::Ordering::Relaxed;

let atomic_arc: AtomicArc<usize> = AtomicArc::new(21);
let barrier = Barrier::new();
let ptr = atomic_arc.load(Relaxed, &barrier);
assert_eq!(*ptr.as_ref().unwrap(), 21);
source

pub fn as_raw(&self) -> *const T

Returns a raw pointer to the instance.

Examples
use scc::ebr::{Arc, Barrier};
use std::sync::atomic::Ordering::Relaxed;

let arc: Arc<usize> = Arc::new(29);
let barrier = Barrier::new();
let ptr = arc.ptr(&barrier);
assert_eq!(unsafe { *ptr.as_raw() }, 29);
source

pub fn tag(&self) -> Tag

Returns its Tag.

Examples
use scc::ebr::{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 scc::ebr::{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 scc::ebr::{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 scc::ebr::{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 scc::ebr::{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_arc(self) -> Option<Arc<T>>

Tries to convert itself into an Arc.

Examples
use scc::ebr::{Arc, Barrier};

let arc: Arc<usize> = Arc::new(83);
let barrier = Barrier::new();
let ptr = arc.ptr(&barrier);
let converted_arc = ptr.get_arc().unwrap();
assert_eq!(*converted_arc, 83);

drop(arc);
drop(converted_arc);

assert!(ptr.get_arc().is_none());

Trait Implementations§

source§

impl<'b, T> Clone for Ptr<'b, 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<'b, T: Debug> Debug for Ptr<'b, T>

source§

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

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

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

source§

fn default() -> Self

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

impl<'b, T> PartialEq<Ptr<'b, T>> for Ptr<'b, 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<'b, T> TryFrom<Ptr<'b, T>> for Arc<T>

§

type Error = Ptr<'b, T>

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

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

Performs the conversion.
source§

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

source§

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

source§

impl<'b, T: UnwindSafe> UnwindSafe for Ptr<'b, T>

Auto Trait Implementations§

§

impl<'b, T> !RefUnwindSafe for Ptr<'b, T>

§

impl<'b, T> !Send for Ptr<'b, T>

§

impl<'b, T> !Sync for Ptr<'b, T>

§

impl<'b, T> Unpin for Ptr<'b, T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.