diff options
Diffstat (limited to '')
| -rw-r--r-- | lib/protocols/Handle.ml | 9 | ||||
| -rw-r--r-- | lib/protocols/Handle.mli | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/protocols/Handle.ml b/lib/protocols/Handle.ml index 524386b..313a3d4 100644 --- a/lib/protocols/Handle.ml +++ b/lib/protocols/Handle.ml @@ -1,5 +1,12 @@ type protocol = .. +module Error = struct + open Concepts.Condition + + let unimplemented_protocol () = condition "unimplemented-protocol" "A required protocol was not implemented by the specified object" + empty +end + class type obj = object method reference : bool method release : unit @@ -45,3 +52,5 @@ let release ({ valid; _ } as handle) = let o = object_of handle in valid := false; o#release + +let require f h = Option.to_result ~none:(Error.unimplemented_protocol ()) (f h) diff --git a/lib/protocols/Handle.mli b/lib/protocols/Handle.mli index f36c95e..f63bbea 100644 --- a/lib/protocols/Handle.mli +++ b/lib/protocols/Handle.mli @@ -22,3 +22,5 @@ val equal : t -> t -> bool val release : t -> unit val hash : t -> Concepts.Hash.hash + +val require : (t -> 'a interface option) -> t -> ('a interface, Concepts.Condition.condition) result |
