|
1 | 1 | open Base |
2 | 2 |
|
3 | | -type 'a or_error = ('a, exn) Result.t |
4 | | -let error exn = Result.Error exn |
5 | | -let ok v = Result.Ok v |
| 3 | +type ('v, 'e) result = ('v, 'e) Result.t |
6 | 4 |
|
7 | 5 | module Record_in = struct |
8 | 6 | type (_, _, _) t = |
@@ -36,15 +34,40 @@ module Variant_in = struct |
36 | 34 | type (_, _) t = Variant: string * ('a, 'constr, 'c) Tuple_in.t * 'constr -> ('a, 'c) t |
37 | 35 | end |
38 | 36 |
|
| 37 | +(** Signature for a driver. Serialization function are on the form [of_XXX] and |
| 38 | + deserialization function are on the form [to_XXX]. |
| 39 | +
|
| 40 | + All deserialization functions should only raise [Protocol_error] is the type could not be desrialized. |
| 41 | +*) |
39 | 42 | module type Driver = sig |
| 43 | + |
| 44 | + (** Serialized type. This type should not be opaque, so it is recommended that |
| 45 | + drivers implement the signature as [Runtime.Driver with type t = ... ] |
| 46 | + *) |
40 | 47 | type t |
41 | | - exception Protocol_error of string * t option |
| 48 | + |
| 49 | + (** Opaque error type *) |
| 50 | + type error |
| 51 | + |
| 52 | + (** Exception for protocol errors. The driver should make sure that |
| 53 | + this is the only exception raised when deserializing *) |
| 54 | + exception Protocol_error of error |
| 55 | + |
| 56 | + (** Convert an error type to a human readable string *) |
| 57 | + val error_to_string_hum: error -> string |
| 58 | + |
| 59 | + (** Convert t to a string *) |
42 | 60 | val to_string_hum: t -> string |
43 | 61 |
|
| 62 | + (** Wrap deserialization function to convert exceptions into an result type *) |
| 63 | + val try_with: (t -> 'v) -> t -> ('v, error) result |
| 64 | + |
44 | 65 | val to_variant: (t, 'a) Variant_in.t list -> t -> 'a |
45 | 66 | val of_variant: string -> (t, 'a, t) Tuple_out.t -> 'a |
| 67 | + |
46 | 68 | val to_record: (t, 'constr, 'b) Record_in.t -> 'constr -> t -> 'b |
47 | 69 | val of_record: (t, 'a, t) Record_out.t -> 'a |
| 70 | + |
48 | 71 | val to_tuple: (t, 'constr, 'b) Tuple_in.t -> 'constr -> t -> 'b |
49 | 72 | val of_tuple: (t, 'a, t) Tuple_out.t -> 'a |
50 | 73 |
|
|
0 commit comments