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
use crate::{InnerPool, PoolValue};

#[derive(Debug)]
pub struct Factory<T: 'static> {
    inner: *mut InnerPool<T>,
}

impl<T> Default for Factory<T> {
    fn default() -> Self {
        Self {
            inner: std::ptr::null_mut(),
        }
    }
}

impl<T> Factory<T> {
    pub(crate) fn new(inner: *mut InnerPool<T>) -> Self {
        Self { inner }
    }

    pub fn alloc(&self, value: T) -> PoolValue<T> {
        let inner_ref = unsafe { self.inner.as_ref().unwrap() };
        inner_ref.alloc(value)
    }
}