package async_kernel

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file job_or_event_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(** [Job_or_event] is a custom zero-alloc sum type that is like:

    {[
      | Event of Event.t
      | Job   of Job.t
    ]}

    except that it uses the fact that [Event.t] is a pointer and [Job.t] is an
    int to be zero alloc. *)

open! Core_kernel
open! Import
module Event = Types.Event

module type Job_or_event = sig
  type t = Types.Job_or_event.t

  val of_event : Event.t -> t
  val of_job : Job.t -> t
  val is_event : t -> bool
  val is_job : t -> bool

  (** Idiomatic usage of [Match] is:

      {[
        let job_or_event = ... in
        let open Job_or_event.Match in
        let K k = kind job_or_event in
        match k, project k job_or_event with
        | Event , event -> ... use event ...
        | Job   , job   -> ... use job ...
      ]} *)
  module Match : sig
    type _ kind =
      | Event : Event.t kind
      | Job : Job.t kind

    type packed = K : _ kind -> packed

    val kind : t -> packed
    val project : 'a kind -> t -> 'a
  end
end
OCaml

Innovation. Community. Security.