Skip to content

Commit

Permalink
add Deser.return
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Oct 13, 2023
1 parent a27a5ca commit 2a40123
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/core/cbor_pack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ module Ser = struct
let[@inline] bytes x : cbor = `Bytes (Bytes.unsafe_to_string x)
let list_of f st x = list (List.map (f st) x)
let map_of fk fv st x = map (List.map (fun (k, v) -> fk st k, fv st v) x)
let[@inline] delay f st x = f () st x

let[@inline] delay f st x = f() st x

let fix (f: 'a t -> 'a t) : 'a t =
let rec _self = lazy (
fun st x -> f (Lazy.force _self) st x
) in Lazy.force _self
let fix (f : 'a t -> 'a t) : 'a t =
let rec _self = lazy (fun st x -> f (Lazy.force _self) st x) in
Lazy.force _self

let add_entry ?(hashcons = false) (self : state) (c : cbor) : ptr =
match c with
Expand Down Expand Up @@ -220,6 +218,7 @@ module Deser = struct

exception Error = CBOR.Error

let return x _st _c = x
let fail s = raise (Error s)
let failf s = Printf.ksprintf fail s

Expand Down Expand Up @@ -307,10 +306,9 @@ module Deser = struct

let[@inline] delay f st x = (f ()) st x

let fix (f: 'a t -> 'a t) : 'a t =
let rec _self = lazy (
fun st x -> f (Lazy.force _self) st x
) in Lazy.force _self
let fix (f : 'a t -> 'a t) : 'a t =
let rec _self = lazy (fun st x -> f (Lazy.force _self) st x) in
Lazy.force _self

let map_entry_no_deref_ ~k (c : cbor) : cbor =
let m = to_map_no_deref_ c in
Expand Down
2 changes: 2 additions & 0 deletions src/core/cbor_pack.mli
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ module Deser : sig
(** Get an item via its pointer.
@raise Invalid_argument if the pointer is invalid. *)

val return : 'a -> 'a t

val fail : string -> 'a
(** Fail to decode. *)

Expand Down

0 comments on commit 2a40123

Please sign in to comment.