[−][src]Struct refpool::PoolRef
A reference counted pointer to A
.
Methods
impl<A, S> PoolRef<A, S> where
S: PoolSyncType<A>,
[src]
S: PoolSyncType<A>,
pub fn default(pool: &Pool<A, S>) -> Self where
A: PoolDefault,
[src]
A: PoolDefault,
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]
A: PoolClone,
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]
A: PoolDefault,
Construct a Pin
ned PoolRef
with a default value.
pub fn pin(pool: &Pool<A, S>, value: A) -> Pin<Self>
[src]
Construct a Pin
ned PoolRef
with the given value.
pub fn cloned(&self, pool: &Pool<A, S>) -> Self where
A: PoolClone,
[src]
A: PoolClone,
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]
A: PoolClone,
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]
A: PoolClone,
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 PoolRef
s 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]
S: PoolSyncType<A>,
impl<A, S> Borrow<A> for PoolRef<A, S> where
S: PoolSyncType<A>,
[src]
S: PoolSyncType<A>,
impl<A, S> Clone for PoolRef<A, S> where
S: PoolSyncType<A>,
[src]
S: PoolSyncType<A>,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A, S> Debug for PoolRef<A, S> where
A: Debug,
S: PoolSyncType<A>,
[src]
A: Debug,
S: PoolSyncType<A>,
impl<A, S> Deref for PoolRef<A, S> where
S: PoolSyncType<A>,
[src]
S: PoolSyncType<A>,
impl<A, S> Display for PoolRef<A, S> where
A: Display,
S: PoolSyncType<A>,
[src]
A: Display,
S: PoolSyncType<A>,
impl<A, S> Drop for PoolRef<A, S> where
S: PoolSyncType<A>,
[src]
S: PoolSyncType<A>,
impl<A, S> Eq for PoolRef<A, S> where
A: Eq,
S: PoolSyncType<A>,
[src]
A: Eq,
S: PoolSyncType<A>,
impl<A, S> Hash for PoolRef<A, S> where
A: Hash,
S: PoolSyncType<A>,
[src]
A: Hash,
S: PoolSyncType<A>,
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<A, S> Ord for PoolRef<A, S> where
A: Ord,
S: PoolSyncType<A>,
[src]
A: Ord,
S: PoolSyncType<A>,
fn cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<A, S> PartialEq<PoolRef<A, S>> for PoolRef<A, S> where
A: PartialEq,
S: PoolSyncType<A>,
[src]
A: PartialEq,
S: PoolSyncType<A>,
impl<A, S> PartialOrd<PoolRef<A, S>> for PoolRef<A, S> where
A: PartialOrd,
S: PoolSyncType<A>,
[src]
A: PartialOrd,
S: PoolSyncType<A>,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, S> Pointer for PoolRef<A, S> where
S: PoolSyncType<A>,
[src]
S: PoolSyncType<A>,
Auto Trait Implementations
impl<A, S> RefUnwindSafe for PoolRef<A, S> where
<S as PoolSyncType<A>>::ElementPointer: RefUnwindSafe,
<S as PoolSyncType<A>>::ElementPointer: RefUnwindSafe,
impl<A, S> Send for PoolRef<A, S> where
<S as PoolSyncType<A>>::ElementPointer: Send,
<S as PoolSyncType<A>>::ElementPointer: Send,
impl<A, S> Sync for PoolRef<A, S> where
<S as PoolSyncType<A>>::ElementPointer: Sync,
<S as PoolSyncType<A>>::ElementPointer: Sync,
impl<A, S> Unpin for PoolRef<A, S> where
<S as PoolSyncType<A>>::ElementPointer: Unpin,
<S as PoolSyncType<A>>::ElementPointer: Unpin,
impl<A, S> UnwindSafe for PoolRef<A, S> where
<S as PoolSyncType<A>>::ElementPointer: UnwindSafe,
<S as PoolSyncType<A>>::ElementPointer: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> 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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,