add result.ml; polymorphic variant errors + refacto

This commit is contained in:
swrup 2026-03-26 06:23:42 +01:00 committed by Swrup
parent 9fd3b5a3cc
commit 42b0ec1445
36 changed files with 949 additions and 954 deletions

11
src/bbin.ml Normal file
View file

@ -0,0 +1,11 @@
let encode bin t =
try Ok (Bin.to_string bin t)
with Invalid_argument e ->
Fmt.error "Bin encode error %s" e
|> Result.map_error (fun e -> `Bin_encode e)
let decode bin o =
try Ok (Bin.decode bin o (ref 0))
with Invalid_argument e ->
Fmt.error "Bin decode error %s" e
|> Result.map_error (fun e -> `Bin_decode e)