add more generic printers for CCError and CCResult (close #73)

This commit is contained in:
Simon Cruanes 2016-06-19 01:02:06 +02:00
parent 103dfb8c73
commit c573f447bc
4 changed files with 33 additions and 0 deletions

View file

@ -260,6 +260,14 @@ let pp pp_x buf e = match e with
| `Ok x -> Printf.bprintf buf "ok(%a)" pp_x x | `Ok x -> Printf.bprintf buf "ok(%a)" pp_x x
| `Error s -> Printf.bprintf buf "error(%s)" s | `Error s -> Printf.bprintf buf "error(%s)" s
let pp' pp_x pp_e buf e = match e with
| `Ok x -> Printf.bprintf buf "ok(%a)" pp_x x
| `Error s -> Printf.bprintf buf "error(%a)" pp_e s
let print pp_x fmt e = match e with let print pp_x fmt e = match e with
| `Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x | `Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x
| `Error s -> Format.fprintf fmt "@[error(@,%s)@]" s | `Error s -> Format.fprintf fmt "@[error(@,%s)@]" s
let print' pp_x pp_e fmt e = match e with
| `Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x
| `Error s -> Format.fprintf fmt "@[error(@,%a)@]" pp_e s

View file

@ -190,8 +190,16 @@ val to_seq : ('a, _) t -> 'a sequence
val pp : 'a printer -> ('a, string) t printer val pp : 'a printer -> ('a, string) t printer
val pp': 'a printer -> 'e printer -> ('a, 'e) t printer
(** Printer that is generic on the error type
@since NEXT_RELEASE *)
val print : 'a formatter -> ('a, string) t formatter val print : 'a formatter -> ('a, string) t formatter
val print' : 'a formatter -> 'e formatter -> ('a, 'e) t formatter
(** Printer that is generic on the error type
@since NEXT_RELEASE *)
(** {2 Global Exception Printers} (** {2 Global Exception Printers}
One can register exception printers here, so they will be used by {!guard}, One can register exception printers here, so they will be used by {!guard},

View file

@ -261,6 +261,14 @@ let pp pp_x buf e = match e with
| Ok x -> Printf.bprintf buf "ok(%a)" pp_x x | Ok x -> Printf.bprintf buf "ok(%a)" pp_x x
| Error s -> Printf.bprintf buf "error(%s)" s | Error s -> Printf.bprintf buf "error(%s)" s
let pp' pp_x pp_e buf e = match e with
| Ok x -> Printf.bprintf buf "ok(%a)" pp_x x
| Error s -> Printf.bprintf buf "error(%a)" pp_e s
let print pp_x fmt e = match e with let print pp_x fmt e = match e with
| Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x | Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x
| Error s -> Format.fprintf fmt "@[error(@,%s)@]" s | Error s -> Format.fprintf fmt "@[error(@,%s)@]" s
let print' pp_x pp_e fmt e = match e with
| Ok x -> Format.fprintf fmt "@[ok(@,%a)@]" pp_x x
| Error s -> Format.fprintf fmt "@[error(@,%a)@]" pp_e s

View file

@ -193,4 +193,13 @@ val to_err : ('a, 'b) t -> ('a, 'b) error
val pp : 'a printer -> ('a, string) t printer val pp : 'a printer -> ('a, string) t printer
val pp': 'a printer -> 'e printer -> ('a, 'e) t printer
(** Printer that is generic on the error type
@since NEXT_RELEASE *)
val print : 'a formatter -> ('a, string) t formatter val print : 'a formatter -> ('a, string) t formatter
val print' : 'a formatter -> 'e formatter -> ('a, 'e) t formatter
(** Printer that is generic on the error type
@since NEXT_RELEASE *)