use crate::storage_id_type;
storage_id_type!(StorageId);
#[derive(Clone, Debug)]
pub enum StorageUtilization {
Full(usize),
Slice {
offset: usize,
size: usize,
},
}
#[derive(new, Clone, Debug)]
pub struct StorageHandle {
pub id: StorageId,
pub utilization: StorageUtilization,
}
impl StorageHandle {
pub fn size(&self) -> usize {
match self.utilization {
StorageUtilization::Full(size) => size,
StorageUtilization::Slice { offset: _, size } => size,
}
}
pub fn offset(&self) -> usize {
match self.utilization {
StorageUtilization::Full(..) => panic!("full size slice not supported anymore"),
StorageUtilization::Slice { offset, .. } => offset,
}
}
}
pub trait ComputeStorage: Send {
type Resource: Send;
fn get(&mut self, handle: &StorageHandle) -> Self::Resource;
fn alloc(&mut self, size: usize) -> StorageHandle;
fn dealloc(&mut self, id: StorageId);
}