pub struct SharedPointer<T, P>where
    P: SharedPointerKind,{ /* private fields */ }
Expand description

Pointer to shared data with reference-counting.

The type parameter P is a type constructor of the underlying pointer type, offering a way to abstraction over Rc and Arc smart pointers. This allows you to create data structures where the pointer type is parameterizable, so you can avoid the overhead of Arc when you don’t need to share data across threads.

Example

Declare a data structure with the pointer kind as a type parameter bounded by SharedPointerKind:

use archery::*;

struct KeyValuePair<K, V, P: SharedPointerKind> {
    pub key: SharedPointer<K, P>,
    pub value: SharedPointer<V, P>,
}

impl<K, V, P: SharedPointerKind> KeyValuePair<K, V, P> {
    fn new(key: K, value: V) -> KeyValuePair<K, V, P> {
        KeyValuePair {
            key: SharedPointer::new(key),
            value: SharedPointer::new(value),
        }
    }
}

To use it just plug-in the kind of pointer you want:

let pair: KeyValuePair<_, _, RcK> =
    KeyValuePair::new("António Variações", 1944);

assert_eq!(*pair.value, 1944);

Implementations§

source§

impl<T, P> SharedPointer<T, P>where P: SharedPointerKind,

source

pub fn new(v: T) -> SharedPointer<T, P>

source

pub fn pin(v: T) -> Pin<SharedPointer<T, P>>

source

pub fn as_ptr(this: &Self) -> *const T

source

pub fn try_unwrap(this: SharedPointer<T, P>) -> Result<T, SharedPointer<T, P>>

source

pub fn get_mut(this: &mut SharedPointer<T, P>) -> Option<&mut T>

source

pub fn strong_count(this: &Self) -> usize

source

pub fn ptr_eq<PO: SharedPointerKind>( this: &SharedPointer<T, P>, other: &SharedPointer<T, PO> ) -> bool

source§

impl<T, P> SharedPointer<T, P>where T: Clone, P: SharedPointerKind,

source

pub fn make_mut(this: &mut SharedPointer<T, P>) -> &mut T

Trait Implementations§

source§

impl<T, P> AsRef<T> for SharedPointer<T, P>where P: SharedPointerKind,

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T, P> Borrow<T> for SharedPointer<T, P>where P: SharedPointerKind,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T, P> Clone for SharedPointer<T, P>where P: SharedPointerKind,

source§

fn clone(&self) -> SharedPointer<T, P>

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<T, P> Debug for SharedPointer<T, P>where T: Debug, P: SharedPointerKind,

source§

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

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

impl<T, P> Default for SharedPointer<T, P>where T: Default, P: SharedPointerKind,

source§

fn default() -> SharedPointer<T, P>

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

impl<T, P> Deref for SharedPointer<T, P>where P: SharedPointerKind,

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T, P> Display for SharedPointer<T, P>where T: Display, P: SharedPointerKind,

source§

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

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

impl<T, P> Drop for SharedPointer<T, P>where P: SharedPointerKind,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T, P> From<Box<T, Global>> for SharedPointer<T, P>where P: SharedPointerKind,

source§

fn from(v: Box<T>) -> SharedPointer<T, P>

Converts to this type from the input type.
source§

impl<T, P> From<T> for SharedPointer<T, P>where P: SharedPointerKind,

source§

fn from(other: T) -> SharedPointer<T, P>

Converts to this type from the input type.
source§

impl<T, P> Hash for SharedPointer<T, P>where T: Hash, P: SharedPointerKind,

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, P> Ord for SharedPointer<T, P>where T: Ord, P: SharedPointerKind,

source§

fn cmp(&self, other: &SharedPointer<T, P>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<T, P, PO> PartialEq<SharedPointer<T, PO>> for SharedPointer<T, P>where T: PartialEq, P: SharedPointerKind, PO: SharedPointerKind,

source§

fn eq(&self, other: &SharedPointer<T, PO>) -> bool

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

fn ne(&self, other: &SharedPointer<T, PO>) -> bool

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

impl<T, P, PO> PartialOrd<SharedPointer<T, PO>> for SharedPointer<T, P>where T: PartialOrd, P: SharedPointerKind, PO: SharedPointerKind,

source§

fn partial_cmp(&self, other: &SharedPointer<T, PO>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
source§

fn lt(&self, other: &SharedPointer<T, PO>) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
source§

fn le(&self, other: &SharedPointer<T, PO>) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
source§

fn gt(&self, other: &SharedPointer<T, PO>) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
source§

fn ge(&self, other: &SharedPointer<T, PO>) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T, P> Pointer for SharedPointer<T, P>where P: SharedPointerKind,

source§

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

Formats the value using the given formatter.
source§

impl<T, P> Eq for SharedPointer<T, P>where T: Eq, P: SharedPointerKind,

source§

impl<T: Sync + Send, P> Send for SharedPointer<T, P>where P: SharedPointerKind + Send,

source§

impl<T: Sync + Send, P> Sync for SharedPointer<T, P>where P: SharedPointerKind + Sync,

source§

impl<T, P> Unpin for SharedPointer<T, P>where P: SharedPointerKind,

Auto Trait Implementations§

§

impl<T, P> RefUnwindSafe for SharedPointer<T, P>where P: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, P> UnwindSafe for SharedPointer<T, P>where P: UnwindSafe, T: UnwindSafe,

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

const: unstable · source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.