Debian Codegraph @

stable_witness/src/stable_witness_intf.ml

raw symbols SCIP
1 module type T1 = sig
2 type _ t
3 end
4
5 module type T2 = sig
6 type (_, _) t
7 end
8
9 module type T3 = sig
10 type (_, _, _) t
11 end
12
13 module type Stable_witness = sig
14 type 'a t
15
16 module Export : sig
17 (** Stable witnesses for primitive types exported by [Core.Core_stable]. Code using
18 [ppx_stable_witness] is expected to start with [open Stable_witness.Export]. *)
19
20 val stable_witness_array : 'a t -> 'a array t
21 val stable_witness_bool : bool t
22 val stable_witness_bytes : bytes t
23 val stable_witness_char : char t
24 val stable_witness_exn : exn t
25 val stable_witness_float : float t
26 val stable_witness_int : int t
27 val stable_witness_int32 : int32 t
28 val stable_witness_int64 : int64 t
29 val stable_witness_lazy_t : 'a t -> 'a lazy_t t
30 val stable_witness_list : 'a t -> 'a list t
31 val stable_witness_nativeint : nativeint t
32 val stable_witness_option : 'a t -> 'a option t
33 val stable_witness_ref : 'a t -> 'a ref t
34 val stable_witness_string : string t
35 val stable_witness_unit : unit t
36 end
37
38 (** This is useful to provide a stable witness on a type that uses another type for
39 serialization. *)
40 val of_serializable : 'a t -> ('a -> 'b) -> ('b -> 'a) -> 'b t
41
42 module type T1 = T1
43
44 module Of_serializable1 (Stable_format : T1) (M : T1) : sig
45 (** This is the analogue of [of_serializable] for types with 1 type parameter, e.g.
46 ['a M.t].
47
48 An example usage would look something like this:
49
50 {[
51 let stable_witness (type a) : a Stable_witness.t -> a M.t Stable_witness.t =
52 fun witness ->
53 let module Stable_witness =
54 Stable_witness.Of_serializable1 (Stable_format) (M)
55 in
56 Stable_witness.of_serializable
57 Stable_format.stable_witness
58 M.of_stable_format
59 M.to_stable_format
60 witness
61 ;;
62 ]}
63 *)
64 val of_serializable
65 : ('a t -> 'a Stable_format.t t) (** witness for stable format *)
66 -> ('a Stable_format.t -> 'a M.t) (** conversion from stable format *)
67 -> ('a M.t -> 'a Stable_format.t) (** conversion to stable format *)
68 -> 'a t
69 -> 'a M.t t
70 end
71
72 module type T2 = T2
73
74 module Of_serializable2 (Stable_format : T2) (M : T2) : sig
75 (** This is the analogue of [of_serializable] for types with 2 type parameters. *)
76 val of_serializable
77 : ('a1 t -> 'a2 t -> ('a1, 'a2) Stable_format.t t) (** witness for stable format *)
78 -> (('a1, 'a2) Stable_format.t -> ('a1, 'a2) M.t) (** from stable format *)
79 -> (('a1, 'a2) M.t -> ('a1, 'a2) Stable_format.t) (** to stable format *)
80 -> 'a1 t
81 -> 'a2 t
82 -> ('a1, 'a2) M.t t
83 end
84
85 module Of_serializable3 (Stable_format : T3) (M : T3) : sig
86 (** This is the analogue of [of_serializable] for types with 3 type parameters. *)
87 val of_serializable
88 : ('a1 t -> 'a2 t -> 'a3 t -> ('a1, 'a2, 'a3) Stable_format.t t)
89 (** witness for stable format *)
90 -> (('a1, 'a2, 'a3) Stable_format.t -> ('a1, 'a2, 'a3) M.t)
91 (** from stable format *)
92 -> (('a1, 'a2, 'a3) M.t -> ('a1, 'a2, 'a3) Stable_format.t) (** to stable format *)
93 -> 'a1 t
94 -> 'a2 t
95 -> 'a3 t
96 -> ('a1, 'a2, 'a3) M.t t
97 end
98
99 (** This is an escape hatch. Don't use it unless you have to.
100
101 There are two use cases for this:
102
103 1. It allows you to assert that a type that you're writing has stable serialization
104 functions, even if the type itself depends on unstable types.
105
106 2. It allows you to assert that a type from some other module is stable (and
107 generate a stable witness for it) even if the type doesn't provide one for itself.
108 It is almost always better to get the upstream code to provide a stability
109 guarantee. At the very least, consult with the upstream maintainer to make sure
110 their serializations are stable over time, and document the discussion. *)
111 val assert_stable : _ t
112 end