alloc_from_pool/
factory.rs

1use std::cell::UnsafeCell;
2
3use crate::{alloc_in::alloc_in, allocations_ptr::allocations_ptr, PoolValue};
4
5#[derive(Debug)]
6pub struct Factory<T> {
7    pub(crate) slots: *const UnsafeCell<Vec<Box<T>>>,
8    #[cfg(test)]
9    pub(crate) allocations: *mut usize,
10}
11
12impl<T> Factory<T> {
13    pub fn alloc(&self, value: T) -> PoolValue<T> {
14        alloc_in(self.slots, allocations_ptr!(self), value)
15    }
16}
17
18impl<T> Default for Factory<T> {
19    fn default() -> Self {
20        Self {
21            slots: std::ptr::null(),
22            #[cfg(test)]
23            allocations: std::ptr::null_mut(),
24        }
25    }
26}