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§
pub fn new(v: T) -> SharedPointer<T, P>
pub fn pin(v: T) -> Pin<SharedPointer<T, P>>
pub fn as_ptr(this: &SharedPointer<T, P>) -> *const T
pub fn try_unwrap(this: SharedPointer<T, P>) -> Result<T, SharedPointer<T, P>>
pub fn get_mut(this: &mut SharedPointer<T, P>) -> Option<&mut T>
pub fn strong_count(this: &SharedPointer<T, P>) -> usize
pub fn ptr_eq<PO>(
this: &SharedPointer<T, P>,
other: &SharedPointer<T, PO>,
) -> boolwhere
PO: SharedPointerKind,
pub fn make_mut(this: &mut SharedPointer<T, P>) -> &mut T
Trait Implementations§
Source§fn clone(&self) -> SharedPointer<T, P>
fn clone(&self) -> SharedPointer<T, P>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§fn default() -> SharedPointer<T, P>
fn default() -> SharedPointer<T, P>
Returns the “default value” for a type. Read more
Source§fn from(v: Box<T>) -> SharedPointer<T, P>
fn from(v: Box<T>) -> SharedPointer<T, P>
Converts to this type from the input type.
Source§fn from(other: T) -> SharedPointer<T, P>
fn from(other: T) -> SharedPointer<T, P>
Converts to this type from the input type.
Source§fn cmp(&self, other: &SharedPointer<T, P>) -> Ordering
fn cmp(&self, other: &SharedPointer<T, P>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§fn eq(&self, other: &SharedPointer<T, PO>) -> bool
fn eq(&self, other: &SharedPointer<T, PO>) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§fn ne(&self, other: &SharedPointer<T, PO>) -> bool
fn ne(&self, other: &SharedPointer<T, PO>) -> bool
Tests for
!=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.Source§fn partial_cmp(&self, other: &SharedPointer<T, PO>) -> Option<Ordering>
fn partial_cmp(&self, other: &SharedPointer<T, PO>) -> Option<Ordering>
Source§fn lt(&self, other: &SharedPointer<T, PO>) -> bool
fn lt(&self, other: &SharedPointer<T, PO>) -> bool
Source§fn le(&self, other: &SharedPointer<T, PO>) -> bool
fn le(&self, other: &SharedPointer<T, PO>) -> bool
Source§fn gt(&self, other: &SharedPointer<T, PO>) -> bool
fn gt(&self, other: &SharedPointer<T, PO>) -> bool
Auto Trait Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more