lockfree_object_pool/
none_reusable.rs

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