use core::ops::{Deref, DerefMut};
use crate::{Alloc, Allocator};
pub struct Handle<'alloc, T: ?Sized> {
alloc: Alloc<'alloc, T>,
allocator: &'alloc dyn Allocator,
}
impl<'alloc, T> Handle<'alloc, T> {
pub fn new(alloc: Alloc<'alloc, T>, allocator: &'alloc dyn Allocator) -> Self {
debug_assert!(alloc.brand() == allocator.brand());
Self { alloc, allocator }
}
pub fn cast<Q>(self) -> Handle<'alloc, Q> {
let Self { alloc, allocator } = self;
Handle {
alloc: alloc.cast(),
allocator,
}
}
}
impl<'alloc, T> Deref for Handle<'alloc, T> {
type Target = Alloc<'alloc, T>;
fn deref(&self) -> &Self::Target {
&self.alloc
}
}
impl<T> DerefMut for Handle<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.alloc
}
}