scale_std 0.1.2

datastructures and algorithms to be run on the SCALE engine
use core::marker::PhantomData;
use scale::alloc::GetAllocator;
use scale::Print;

pub struct Guard<'a, T>
where
    T: GetAllocator,
{
    pub(crate) phantom: PhantomData<&'a T>,
    pub(crate) inner: T,
}

impl<'a, T> core::ops::Deref for Guard<'a, T>
where
    T: GetAllocator,
{
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}

pub struct GuardMut<'a, T>
where
    T: GetAllocator,
{
    pub(crate) phantom: PhantomData<&'a mut T>,
    pub(crate) inner: T,
}

impl<'a, T> core::ops::Deref for GuardMut<'a, T>
where
    T: GetAllocator,
{
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}

impl<'a, T> core::ops::DerefMut for GuardMut<'a, T>
where
    T: GetAllocator,
{
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.inner
    }
}

impl<'a, T> Print for Guard<'a, T>
where
    T: GetAllocator + Print,
{
    #[inline(always)]
    fn print(self) {
        self.inner.print();
    }
}

impl<'a, T> Print for GuardMut<'a, T>
where
    T: GetAllocator + Print,
{
    #[inline(always)]
    fn print(self) {
        self.inner.print();
    }
}