Skip to content

Commit

Permalink
Apply the interface trick to the storage module.
Browse files Browse the repository at this point in the history
This reduces code duplication of types and signatures in the directory.
  • Loading branch information
zoj613 committed Jul 3, 2024
1 parent b47ad5c commit 740adb8
Show file tree
Hide file tree
Showing 7 changed files with 572 additions and 465 deletions.
93 changes: 0 additions & 93 deletions lib/storage/base.ml

This file was deleted.

18 changes: 11 additions & 7 deletions lib/storage/filesystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module Impl = struct
(fun oc -> Out_channel.output_string oc value)

let list t =
let module StrSet = Base.StrSet in
let module StrSet = Storage_intf.Base.StrSet in
let rec aux acc path =
try
match Sys.readdir path with
Expand Down Expand Up @@ -70,22 +70,26 @@ module Impl = struct
| Sys_error _ -> ()

let get_partial_values t kr_pairs =
Base.get_partial_values ~get_fn:get t kr_pairs
Storage_intf.Base.get_partial_values
~get_fn:get t kr_pairs

let set_partial_values t krv_triplet =
Base.set_partial_values ~set_fn:set ~get_fn:get t krv_triplet
Storage_intf.Base.set_partial_values
~set_fn:set ~get_fn:get t krv_triplet

let erase_values t keys =
Base.erase_values ~erase_fn:erase t keys
Storage_intf.Base.erase_values
~erase_fn:erase t keys

let erase_prefix t pre =
Base.erase_prefix ~list_fn:list ~erase_fn:erase t pre
Storage_intf.Base.erase_prefix
~list_fn:list ~erase_fn:erase t pre

let list_prefix pre t =
Base.list_prefix ~list_fn:list t pre
Storage_intf.Base.list_prefix ~list_fn:list t pre

let list_dir t pre =
Base.list_dir ~list_fn:list t pre
Storage_intf.Base.list_dir ~list_fn:list t pre
end

let create ?(file_perm=0o640) path =
Expand Down
Loading

0 comments on commit 740adb8

Please sign in to comment.