package ppx_meta_conv

  1. Overview
  2. Docs
Useful tool functions for writing encoders+decoders of primitive types
val integer_of_float : float -> float -> (float -> 'int) -> float -> ('int, string) Result.t

float to integer conversion with error checks.

This is not target type dependent, but it is here for easier access.

val list_of : (target -> target list option) -> 'a decoder -> 'a list decoder

typical list_of_<targe_type>. It takes a function to get a list from a target value

val array_of : (target -> target list option) -> 'a decoder -> 'a array decoder

typical array_of_<targe_type>. It takes a function to get a list from a target value

val option_of : (target -> target option option) -> 'a decoder -> 'a option decoder

typical option_of_<targe_type>. It takes predicate to check the arg is a Some, None or something else.

Some (Some v) : Some for a target value v Some None : None None : : Error. Target value cannot have the option type

val ref_of : (target -> target option) -> 'a decoder -> 'a ref decoder

typical ref_of_<targe_type>. It takes predicate to check the arg is a reference or something else.

Some v : Found a record contents = <v> None : Error. Target value cannot have the option type

val lazy_t_of : (target Error.t -> 'a) -> 'a decoder -> 'a lazy_t decoder

typical lazy_t_of_<targe_type>. The decoding is done lazily. Error at the deferred decoding is handled by the error handler, normally it should raises <Target_conv>.Exception exception.

val of_mc_lazy_t : 'a encoder -> ('a, target) Open.mc_lazy_t encoder

typical <targe_type>_of_mc_lazy_t

val mc_lazy_t_of : 'a decoder -> ('a, target) Open.mc_lazy_t decoder

typical mc_lazy_t_of_<targe_type> The decoding is done lazily. Error at the lazy decoding is reported by the result monad.

val mc_fields_of : (target -> (string * target) list option) -> 'a decoder -> (string * 'a) list decoder

typical mc_fields_of_<targe_type>

val of_deconstr : (target -> 'a) -> 'a decoder

Convert a simple raw deconstr of type target -> 'a to 'a decoder. Error must be reported as Failure s. The other exceptions simply escape.

val of_hashtbl : (target encoder -> target list encoder) -> 'a encoder -> 'b encoder -> ('a, 'b) Hashtbl.t encoder
val hashtbl_of : (('a * 'b) decoder -> ('a * 'b) list decoder) -> 'a decoder -> 'b decoder -> ('a, 'b) Hashtbl.t decoder
val of_result : (target -> target) -> (target -> target) -> 'a encoder -> 'b encoder -> ('a, 'b) result encoder
val result_of : (target, target) result decoder -> 'a decoder -> 'b decoder -> ('a, 'b) result decoder