aboutsummaryrefslogtreecommitdiffstats
path: root/lib/protocols/Handle.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-09-25 21:51:33 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-09-25 21:51:33 -0300
commit584fbca6d920e9a9f91d451667f9380714ac2175 (patch)
treea163b916a6f8cb550c8b38ceb01ab01558687a40 /lib/protocols/Handle.ml
parentc7b754e96714eeeb9d315ee3de402d73a27d47db (diff)
downloadRNT-584fbca6d920e9a9f91d451667f9380714ac2175.tar.gz
RNT-584fbca6d920e9a9f91d451667f9380714ac2175.zip
dune fmt
Diffstat (limited to '')
-rw-r--r--lib/protocols/Handle.ml41
-rw-r--r--lib/protocols/Handle.mli7
2 files changed, 14 insertions, 34 deletions
diff --git a/lib/protocols/Handle.ml b/lib/protocols/Handle.ml
index 41c88dd..cdadd4a 100644
--- a/lib/protocols/Handle.ml
+++ b/lib/protocols/Handle.ml
@@ -4,7 +4,8 @@ module Error = struct
open Concepts.Condition
let unimplemented_protocol obj_name =
- condition "unimplemented-protocol" "A required protocol was not implemented by the specified object"
+ condition "unimplemented-protocol"
+ "A required protocol was not implemented by the specified object"
("object" |=| Concepts.Value.String obj_name)
end
@@ -16,46 +17,32 @@ class type obj = object
method protocols : protocol list
end
-type t = { valid : bool ref; refers_to : obj }
+type t = {valid: bool ref; refers_to: obj}
+type 'a interface = {handle: t; interface: 'a}
-type 'a interface = { handle : t; interface : 'a }
+let object_of {valid; refers_to} =
+ if !valid then refers_to else failwith "Attempt to dereference an invalid handle!"
-let object_of { valid; refers_to } =
- if !valid then
- refers_to
- else
- failwith "Attempt to dereference an invalid handle!"
+let interface_of handle interface = {handle; interface}
+let make o = {valid= ref true; refers_to= (o :> obj)}
+let into handle f = List.find_map f (object_of handle)#protocols |> Option.map (interface_of handle)
-let interface_of handle interface = { handle; interface }
-
-let make o = { valid = ref true; refers_to = (o :> obj) }
-
-let into handle f =
- List.find_map f (object_of handle)#protocols
- |> Option.map (interface_of handle)
-
-let invoke { handle; interface } f =
+let invoke {handle; interface} f =
let _ = object_of handle in
f interface
-let from { handle; _ } = handle
+let from {handle; _} = handle
let copy handle =
let o = object_of handle in
- if o#reference then
- Some (make o)
- else
- None
-
-let equal h1 h2 =
- Concepts.Hash.hash_equals (object_of h1)#hash (object_of h2)#hash
+ if o#reference then Some (make o) else None
+let equal h1 h2 = Concepts.Hash.hash_equals (object_of h1)#hash (object_of h2)#hash
let hash h = (object_of h)#hash
let protocols h = (object_of h)#protocols
-
let to_string h = (object_of h)#to_string
-let release ({ valid; _ } as handle) =
+let release ({valid; _} as handle) =
let o = object_of handle in
valid := false;
o#release
diff --git a/lib/protocols/Handle.mli b/lib/protocols/Handle.mli
index 40a78ff..a354257 100644
--- a/lib/protocols/Handle.mli
+++ b/lib/protocols/Handle.mli
@@ -1,7 +1,5 @@
type t
-
type 'a interface
-
type protocol = ..
class type obj = object
@@ -13,18 +11,13 @@ class type obj = object
end
val make : #obj -> t
-
val into : t -> (protocol -> 'a option) -> 'a interface option
val from : 'a interface -> t
-
val invoke : 'a interface -> ('a -> 'b) -> 'b
-
val copy : t -> t option
val equal : t -> t -> bool
val release : t -> unit
-
val hash : t -> Concepts.Hash.hash
val protocols : t -> protocol list
val to_string : t -> string
-
val require : (t -> 'a interface option) -> t -> ('a interface, Concepts.Condition.condition) result