use std::{alloc::Allocator, io};
use memmap2::{MmapMut, MmapRaw};
use thiserror::Error;
#[derive(Error, Debug)]
enum Error {
#[error(transparent)]
Io(#[from] io::Error),
}
type Result<T, E = Error> = std::result::Result<T, E>;
struct EphemralPoolAllocator {
raw_pool: memmap2::MmapRaw,
}
struct EphemralPoolAllocatorUnit {
dealloc_callback: Box<dyn FnOnce()>,
}
unsafe impl Allocator for EphemralPoolAllocatorUnit {
fn allocate(
&self,
layout: std::alloc::Layout,
) -> Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError> {
todo!()
}
unsafe fn deallocate(&self, ptr: std::ptr::NonNull<u8>, layout: std::alloc::Layout) {
todo!()
}
}
impl EphemralPoolAllocator {
fn new(size: usize) -> Result<Self> {
Ok(Self {
raw_pool: MmapMut::map_anon(size)?.into(),
})
}
}