[][src]Struct refpool::PoolRef

pub struct PoolRef<A> { /* fields omitted */ }

A reference counted pointer to A.

Methods

impl<A> PoolRef<A>[src]

pub fn default(pool: &mut Pool<A>) -> 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: &mut Pool<A>, 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: &mut Pool<A>, 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: &mut Pool<A>) -> Pin<Self> where
    A: PoolDefault
[src]

Construct a Pinned PoolRef with a default value.

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

Construct a Pinned PoolRef with the given value.

pub fn cloned(&self, pool: &mut Pool<A>) -> 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: &mut Pool<A>, 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> Drop for PoolRef<A>[src]

impl<A> AsRef<A> for PoolRef<A>[src]

impl<A> Clone for PoolRef<A>[src]

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

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

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

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

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

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

impl<A> Deref for PoolRef<A>[src]

type Target = A

The resulting type after dereferencing.

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

impl<A> Pointer for PoolRef<A>[src]

impl<A> Borrow<A> for PoolRef<A>[src]

Auto Trait Implementations

impl<A> !Send for PoolRef<A>

impl<A> !Sync for PoolRef<A>

impl<A> Unpin for PoolRef<A>

impl<A> UnwindSafe for PoolRef<A> where
    A: RefUnwindSafe

impl<A> RefUnwindSafe for PoolRef<A> where
    A: RefUnwindSafe

Blanket Implementations

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

impl<T> From<T> for 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 = Infallible

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.

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

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

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