[−][src]Struct archery::shared_pointer::SharedPointer
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<_, _, SharedPointerKindRc> = KeyValuePair::new("António Variações", 1944); assert_eq!(*pair.value, 1944);
Methods
impl<T, P> SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
pub fn new(v: T) -> SharedPointer<T, P>
[src]
pub fn try_unwrap(this: SharedPointer<T, P>) -> Result<T, SharedPointer<T, P>>
[src]
pub fn get_mut(this: &mut SharedPointer<T, P>) -> Option<&mut T>
[src]
pub fn strong_count(this: &Self) -> usize
[src]
pub fn ptr_eq<PO: SharedPointerKind>(
this: &SharedPointer<T, P>,
other: &SharedPointer<T, PO>
) -> bool
[src]
this: &SharedPointer<T, P>,
other: &SharedPointer<T, PO>
) -> bool
impl<T, P> SharedPointer<T, P> where
T: Clone,
P: SharedPointerKind,
[src]
T: Clone,
P: SharedPointerKind,
pub fn make_mut(this: &mut SharedPointer<T, P>) -> &mut T
[src]
Trait Implementations
impl<T, P> Drop for SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
impl<T, P, PO> PartialOrd<SharedPointer<T, PO>> for SharedPointer<T, P> where
T: PartialOrd,
P: SharedPointerKind,
PO: SharedPointerKind,
[src]
T: PartialOrd,
P: SharedPointerKind,
PO: SharedPointerKind,
fn partial_cmp(&self, other: &SharedPointer<T, PO>) -> Option<Ordering>
[src]
fn lt(&self, other: &SharedPointer<T, PO>) -> bool
[src]
fn le(&self, other: &SharedPointer<T, PO>) -> bool
[src]
fn gt(&self, other: &SharedPointer<T, PO>) -> bool
[src]
fn ge(&self, other: &SharedPointer<T, PO>) -> bool
[src]
impl<T, P> AsRef<T> for SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
impl<T, P, PO> PartialEq<SharedPointer<T, PO>> for SharedPointer<T, P> where
T: PartialEq,
P: SharedPointerKind,
PO: SharedPointerKind,
[src]
T: PartialEq,
P: SharedPointerKind,
PO: SharedPointerKind,
fn eq(&self, other: &SharedPointer<T, PO>) -> bool
[src]
fn ne(&self, other: &SharedPointer<T, PO>) -> bool
[src]
impl<T, P> Default for SharedPointer<T, P> where
T: Default,
P: SharedPointerKind,
[src]
T: Default,
P: SharedPointerKind,
fn default() -> SharedPointer<T, P>
[src]
impl<T, P> From<T> for SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
fn from(other: T) -> SharedPointer<T, P>
[src]
impl<T, P> From<Box<T>> for SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
fn from(v: Box<T>) -> SharedPointer<T, P>
[src]
impl<T, P> Clone for SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
fn clone(&self) -> SharedPointer<T, P>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T, P> Ord for SharedPointer<T, P> where
T: Ord,
P: SharedPointerKind,
[src]
T: Ord,
P: SharedPointerKind,
fn cmp(&self, other: &SharedPointer<T, P>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl<T, P> Eq for SharedPointer<T, P> where
T: Eq,
P: SharedPointerKind,
[src]
T: Eq,
P: SharedPointerKind,
impl<T, P> Display for SharedPointer<T, P> where
T: Display,
P: SharedPointerKind,
[src]
T: Display,
P: SharedPointerKind,
impl<T, P> Debug for SharedPointer<T, P> where
T: Debug,
P: SharedPointerKind,
[src]
T: Debug,
P: SharedPointerKind,
impl<T, P> Hash for SharedPointer<T, P> where
T: Hash,
P: SharedPointerKind,
[src]
T: Hash,
P: SharedPointerKind,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T, P> Deref for SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
impl<T, P> Pointer for SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
impl<T, P> Borrow<T> for SharedPointer<T, P> where
P: SharedPointerKind,
[src]
P: SharedPointerKind,
Auto Trait Implementations
impl<T, P> Send for SharedPointer<T, P> where
P: Send,
T: Send,
P: Send,
T: Send,
impl<T, P> Sync for SharedPointer<T, P> where
P: Sync,
T: Sync,
P: Sync,
T: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,