lockfree_object_pool/none_reusable.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
use std::ops::{Deref, DerefMut};
#[allow(unused_imports)]
use crate::none_object_pool::NoneObjectPool;
/// Wrapper over T used by [`NoneObjectPool`].
///
/// Access is allowed with [`std::ops::Deref`] or [`std::ops::DerefMut`]
/// # Example
/// ```rust
/// use lockfree_object_pool::NoneObjectPool;
///
/// let pool = NoneObjectPool::<u32>::new(|| Default::default());
/// let mut item = pool.pull();
///
/// *item = 5;
/// let work = *item * 5;
/// ```
pub struct NoneReusable<T> {
data: T,
}
impl<T> NoneReusable<T> {
/// Create new element
///
/// # Arguments
/// * `data` element to wrappe
#[inline]
pub fn new(data: T) -> Self {
Self { data }
}
}
impl<T> DerefMut for NoneReusable<T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.data
}
}
impl<T> Deref for NoneReusable<T> {
type Target = T;
#[inline]
fn deref(&self) -> &Self::Target {
&self.data
}
}