#[derive(Debug)]
pub struct RcMemorySource<MS: MemorySource>(Rc<MS>);
impl<MS: MemorySource> Clone for RcMemorySource<MS>
{
#[inline(always)]
fn clone(&self) -> Self
{
Self(self.0.clone())
}
}
impl<MS: MemorySource> Deref for RcMemorySource<MS>
{
type Target = MS;
#[inline(always)]
fn deref(&self) -> &Self::Target
{
&self.0
}
}
impl<MS: MemorySource> MemorySource for RcMemorySource<MS>
{
#[inline(always)]
fn obtain(&self, non_zero_size: NonZeroUsize) -> Result<MemoryAddress, AllocErr>
{
self.0.obtain(non_zero_size)
}
#[inline(always)]
fn release(&self, non_zero_size: NonZeroUsize, current_memory: MemoryAddress)
{
self.0.release(non_zero_size, current_memory)
}
}
impl<MS: MemorySource> RcMemorySource<MS>
{
#[inline(always)]
pub fn new_thread_local<GTACSA: GlobalThreadAndCoroutineSwitchableAllocator>(global_allocator: >ACSA, underlying_memory_source: MS) -> Self
{
Self(global_allocator.callback_with_thread_local_allocator(|| Rc::new(underlying_memory_source)))
}
#[inline(always)]
pub fn new_coroutine_local<GTACSA: GlobalThreadAndCoroutineSwitchableAllocator>(global_allocator: >ACSA, underlying_memory_source: MS) -> Self
{
Self(global_allocator.callback_with_coroutine_local_allocator(|| Rc::new(underlying_memory_source)))
}
}