diff options
Diffstat (limited to 'src/Erebos/Storage/Backend.hs')
| -rw-r--r-- | src/Erebos/Storage/Backend.hs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Erebos/Storage/Backend.hs b/src/Erebos/Storage/Backend.hs new file mode 100644 index 0000000..07bd63e --- /dev/null +++ b/src/Erebos/Storage/Backend.hs @@ -0,0 +1,40 @@ +{-| +Description: Implement custom storage backend + +Exports type class, which can be used to create custom 'Storage' backend. +-} + +module Erebos.Storage.Backend ( + StorageBackend(..), + Complete, Partial, + Storage, PartialStorage, + newStorage, + withStorageBackend, + + refDigestBytes, + + WatchID, startWatchID, nextWatchID, +) where + +import Control.Concurrent.MVar + +import Data.ByteArray qualified as BA +import Data.ByteString (ByteString) +import Data.HashTable.IO qualified as HT + +import Erebos.Object.Internal +import Erebos.Storage.Internal + + +newStorage :: StorageBackend bck => bck -> IO (Storage' (BackendCompleteness bck)) +newStorage stBackend = do + stRefGeneration <- newMVar =<< HT.new + stRefRoots <- newMVar =<< HT.new + return Storage {..} + +withStorageBackend :: Storage' c -> (forall bck. (StorageBackend bck, BackendCompleteness bck ~ c) => bck -> IO a) -> IO a +withStorageBackend Storage {..} f = f stBackend + + +refDigestBytes :: RefDigest -> ByteString +refDigestBytes = BA.convert |