123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112moduletypeT1=sigtype_tendmoduletypeT2=sigtype(_,_)tendmoduletypeT3=sigtype(_,_,_)tendmoduletypeStable_witness=sigtype'atmoduleExport:sig(** Stable witnesses for primitive types exported by [Core.Core_stable]. Code using
[ppx_stable_witness] is expected to start with [open Stable_witness.Export]. *)valstable_witness_array:'at->'aarraytvalstable_witness_bool:booltvalstable_witness_bytes:bytestvalstable_witness_char:chartvalstable_witness_exn:exntvalstable_witness_float:floattvalstable_witness_int:inttvalstable_witness_int32:int32tvalstable_witness_int64:int64tvalstable_witness_lazy_t:'at->'alazy_ttvalstable_witness_list:'at->'alisttvalstable_witness_nativeint:nativeinttvalstable_witness_option:'at->'aoptiontvalstable_witness_ref:'at->'areftvalstable_witness_string:stringtvalstable_witness_unit:unittend(** This is useful to provide a stable witness on a type that uses another type for
serialization. *)valof_serializable:'at->('a->'b)->('b->'a)->'btmoduletypeT1=T1moduleOf_serializable1(Stable_format:T1)(M:T1):sig(** This is the analogue of [of_serializable] for types with 1 type parameter, e.g.
['a M.t].
An example usage would look something like this:
{[
let stable_witness (type a) : a Stable_witness.t -> a M.t Stable_witness.t =
fun witness ->
let module Stable_witness =
Stable_witness.Of_serializable1 (Stable_format) (M)
in
Stable_witness.of_serializable
Stable_format.stable_witness
M.of_stable_format
M.to_stable_format
witness
;;
]}
*)valof_serializable:('at->'aStable_format.tt)(** witness for stable format *)->('aStable_format.t->'aM.t)(** conversion from stable format *)->('aM.t->'aStable_format.t)(** conversion to stable format *)->'at->'aM.ttendmoduletypeT2=T2moduleOf_serializable2(Stable_format:T2)(M:T2):sig(** This is the analogue of [of_serializable] for types with 2 type parameters. *)valof_serializable:('a1t->'a2t->('a1,'a2)Stable_format.tt)(** witness for stable format *)->(('a1,'a2)Stable_format.t->('a1,'a2)M.t)(** from stable format *)->(('a1,'a2)M.t->('a1,'a2)Stable_format.t)(** to stable format *)->'a1t->'a2t->('a1,'a2)M.ttendmoduleOf_serializable3(Stable_format:T3)(M:T3):sig(** This is the analogue of [of_serializable] for types with 3 type parameters. *)valof_serializable:('a1t->'a2t->'a3t->('a1,'a2,'a3)Stable_format.tt)(** witness for stable format *)->(('a1,'a2,'a3)Stable_format.t->('a1,'a2,'a3)M.t)(** from stable format *)->(('a1,'a2,'a3)M.t->('a1,'a2,'a3)Stable_format.t)(** to stable format *)->'a1t->'a2t->'a3t->('a1,'a2,'a3)M.ttend(** This is an escape hatch. Don't use it unless you have to.
There are two use cases for this:
1. It allows you to assert that a type that you're writing has stable serialization
functions, even if the type itself depends on unstable types.
2. It allows you to assert that a type from some other module is stable (and
generate a stable witness for it) even if the type doesn't provide one for itself.
It is almost always better to get the upstream code to provide a stability
guarantee. At the very least, consult with the upstream maintainer to make sure
their serializations are stable over time, and document the discussion. *)valassert_stable:_tend