use o3::buffer::resident;
use crate::driver::storage::{Exhausted, resident::Alloc};
pub(super) fn claim<'d>(alloc: Alloc<'d>) -> Result<(usize, &'d mut resident::Domain), Exhausted> {
let index = alloc.arena.next.get();
let Some(slot) = alloc.arena.slots.get(index) else {
return Err(Exhausted::Domains {
capacity: alloc.arena.slots.len(),
});
};
alloc.arena.next.set(index + 1);
let domain = unsafe { &mut *slot.get() };
Ok((index, domain))
}