[][src]Struct refpool::PoolRef

pub struct PoolRef<A, S> where
    S: PoolSyncType<A>, 
{ /* fields omitted */ }

A reference counted pointer to A.

Methods

impl<A, S> PoolRef<A, S> where
    S: PoolSyncType<A>, 
[src]

pub fn default(pool: &Pool<A, S>) -> Self where
    A: PoolDefault
[src]

Construct a PoolRef with a newly initialised value of A.

This uses PoolDefault::default_uninit() to initialise a default value, which may be faster than constructing a PoolRef from an existing value using PoolRef::new(), depending on the data type.

pub fn new(pool: &Pool<A, S>, value: A) -> Self[src]

Wrap a value in a PoolRef.

This will copy the entire value into the memory handled by the PoolRef, which may be slower than using PoolRef::default(), so it's not recommended to use this to construct the default value.

pub fn clone_from(pool: &Pool<A, S>, value: &A) -> Self where
    A: PoolClone
[src]

Clone a value and return a new PoolRef to it.

This will use PoolClone::clone_uninit() to perform the clone, which may be more efficient than using PoolRef::new(value.clone()).

Examples

let mut pool: Pool<Vec<usize>> = Pool::new(1);
let vec = vec![1, 2, 3];
let ref1 = PoolRef::clone_from(&mut pool, &vec);
assert_eq!(vec, *ref1);

pub fn pin_default(pool: &Pool<A, S>) -> Pin<Self> where
    A: PoolDefault
[src]

Construct a Pinned PoolRef with a default value.

pub fn pin(pool: &Pool<A, S>, value: A) -> Pin<Self>[src]

Construct a Pinned PoolRef with the given value.

pub fn cloned(&self, pool: &Pool<A, S>) -> Self where
    A: PoolClone
[src]

Clone the value inside a PoolRef and return a new PoolRef to it.

This will use PoolClone::clone_uninit() to perform the clone, which may be more efficient than using PoolRef::new((*this_ref).clone()).

pub fn make_mut<'a>(pool: &Pool<A, S>, this: &'a mut Self) -> &'a mut A where
    A: PoolClone
[src]

Get a mutable reference to the value inside a PoolRef, cloning it first if this PoolRef isn't a unique reference.

Examples

let mut pool: Pool<usize> = Pool::new(1);
let ref1 = PoolRef::new(&mut pool, 1);
let mut ref2 = ref1.clone();
*PoolRef::make_mut(&mut pool, &mut ref2) = 2;
assert_eq!(1, *ref1);
assert_eq!(2, *ref2);

pub fn get_mut(this: &mut Self) -> Option<&mut A>[src]

Attempt to get a mutable reference to the value inside a PoolRef.

This will produce a None if this PoolRef isn't a unique reference to the value.

pub fn try_unwrap(this: Self) -> Result<A, Self>[src]

Attempt to unwrap the value inside a PoolRef.

If this PoolRef isn't the only reference to the value, ownership of the PoolRef is passed back to you in the Err value.

Please note that the unwrapped value is not reclaimed by the pool when dropped.

Examples

let mut pool: Pool<usize> = Pool::new(1);
let ref1 = PoolRef::default(&mut pool);
let ref2 = ref1.clone();
let unwrap_result = PoolRef::try_unwrap(ref1);
assert!(unwrap_result.is_err());
let mut pool: Pool<usize> = Pool::new(1);
let ref1 = PoolRef::new(&mut pool, 1337);
if let Ok(number) = PoolRef::try_unwrap(ref1) {
    assert_eq!(1337, number);
} else {
    panic!("couldn't unwrap the number after all!");
}

pub fn unwrap_or_clone(this: Self) -> A where
    A: PoolClone
[src]

Unwrap the value inside a PoolRef, cloning if necessary.

If this PoolRef is a unique reference to the value, the value is unwrapped and returned, consuming the PoolRef. Otherwise, the value is cloned and the clone is returned.

Please note that the unwrapped value is not reclaimed by the pool when dropped.

pub fn ptr_eq(left: &Self, right: &Self) -> bool[src]

Test two PoolRefs for pointer equality.

Examples

let mut pool: Pool<usize> = Pool::new(1);
let ref1 = PoolRef::default(&mut pool);
let ref2 = ref1.clone();
assert!(PoolRef::ptr_eq(&ref1, &ref2));

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

Get the current number of LocalRef references to the wrapped value.

Trait Implementations

impl<A, S> AsRef<A> for PoolRef<A, S> where
    S: PoolSyncType<A>, 
[src]

impl<A, S> Borrow<A> for PoolRef<A, S> where
    S: PoolSyncType<A>, 
[src]

impl<A, S> Clone for PoolRef<A, S> where
    S: PoolSyncType<A>, 
[src]

impl<A, S> Debug for PoolRef<A, S> where
    A: Debug,
    S: PoolSyncType<A>, 
[src]

impl<A, S> Deref for PoolRef<A, S> where
    S: PoolSyncType<A>, 
[src]

type Target = A

The resulting type after dereferencing.

impl<A, S> Display for PoolRef<A, S> where
    A: Display,
    S: PoolSyncType<A>, 
[src]

impl<A, S> Drop for PoolRef<A, S> where
    S: PoolSyncType<A>, 
[src]

impl<A, S> Eq for PoolRef<A, S> where
    A: Eq,
    S: PoolSyncType<A>, 
[src]

impl<A, S> Hash for PoolRef<A, S> where
    A: Hash,
    S: PoolSyncType<A>, 
[src]

impl<A, S> Ord for PoolRef<A, S> where
    A: Ord,
    S: PoolSyncType<A>, 
[src]

impl<A, S> PartialEq<PoolRef<A, S>> for PoolRef<A, S> where
    A: PartialEq,
    S: PoolSyncType<A>, 
[src]

impl<A, S> PartialOrd<PoolRef<A, S>> for PoolRef<A, S> where
    A: PartialOrd,
    S: PoolSyncType<A>, 
[src]

impl<A, S> Pointer for PoolRef<A, S> where
    S: PoolSyncType<A>, 
[src]

Auto Trait Implementations

impl<A, S> RefUnwindSafe for PoolRef<A, S> where
    <S as PoolSyncType<A>>::ElementPointer: RefUnwindSafe

impl<A, S> Send for PoolRef<A, S> where
    <S as PoolSyncType<A>>::ElementPointer: Send

impl<A, S> Sync for PoolRef<A, S> where
    <S as PoolSyncType<A>>::ElementPointer: Sync

impl<A, S> Unpin for PoolRef<A, S> where
    <S as PoolSyncType<A>>::ElementPointer: Unpin

impl<A, S> UnwindSafe for PoolRef<A, S> where
    <S as PoolSyncType<A>>::ElementPointer: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.