Struct archery::shared_pointer::SharedPointer
source · 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: &Self) -> *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: &Self) -> usize
pub fn ptr_eq<PO: SharedPointerKind>( this: &SharedPointer<T, P>, other: &SharedPointer<T, PO> ) -> bool
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 copy 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 deserialize<D: Deserializer<'de>>(
deserializer: D
) -> Result<SharedPointer<T, P>, D::Error>
fn deserialize<D: Deserializer<'de>>( deserializer: D ) -> Result<SharedPointer<T, P>, D::Error>
Deserialize this value from the given Serde deserializer. 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
This method 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
This method 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
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§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