#ifdef LANGUAGE_Trustworthy
#endif
module Data.Var.ByteArray
( ByteArrayVar
) where
import Control.Monad.Prim
import Data.ByteArraySlice.Unsafe
import Data.Prim.ByteArray
import Data.Var.Class
import Data.Typeable (Typeable)
newtype ByteArrayVar s a = ByteArrayVar (MutableByteArray s) deriving (Eq, Typeable)
instance ( ByteArraySlice a
, MonadPrim m
, s ~ World m
) => Var (ByteArrayVar s) a m where
newVar a = runPrim $ do
array <- newByteArray (byteSizeOf a)
writeByteOff array 0 a
return $ ByteArrayVar array
readVar (ByteArrayVar array) = runPrim $ readByteOff array 0
writeVar (ByteArrayVar array) = runPrim . writeByteOff array 0