aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-02-20 10:16:52 -0700
committerAdelyn Breedlove <[email protected]>2019-02-20 10:16:52 -0700
commit4295208b94245ee513eaabd06381b7f700376115 (patch)
treee1abac09378d4b55a29df37f51fa93182a60023f
parentAdd permissions to role models (diff)
downloaddisml-4295208b94245ee513eaabd06381b7f700376115.tar.xz
disml-4295208b94245ee513eaabd06381b7f700376115.zip
Fix permissions and add more conversions
-rw-r--r--lib/models/permissions.ml14
-rw-r--r--lib/models/permissions.mli9
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/models/permissions.ml b/lib/models/permissions.ml
index 1521a0e..2b217b8 100644
--- a/lib/models/permissions.ml
+++ b/lib/models/permissions.ml
@@ -28,13 +28,25 @@ type elt =
| MANAGE_ROLES
| MANAGE_WEBHOOKS
| MANAGE_EMOJIS
+[@@deriving sexp]
include BitMaskSet.Make(struct
include BitMaskSet.Int
type t = elt
- let mask = 0b0111_1111_1111_1111_0111_1101_1111_1111
+ let mask = 0b0111_1111_1111_0111_1111_1101_1111_1111
end)
+let sexp_of_t = Core.Int.sexp_of_t
+let t_of_sexp = Core.Int.t_of_sexp
+
+let of_yojson_exn j = create @@ Yojson.Safe.Util.to_int j
+
+let of_yojson j =
+ try Ok (of_yojson_exn j)
+ with Yojson.Safe.Util.Type_error (why,_) -> Error why
+
+let to_yojson t : Yojson.Safe.t = `Int t
+
let of_seq seq = List.of_seq seq |> of_list
let to_seq mask = elements mask |> List.to_seq
diff --git a/lib/models/permissions.mli b/lib/models/permissions.mli
index 74ed563..6e4d30a 100644
--- a/lib/models/permissions.mli
+++ b/lib/models/permissions.mli
@@ -28,7 +28,14 @@ type elt =
| MANAGE_ROLES
| MANAGE_WEBHOOKS
| MANAGE_EMOJIS
+[@@deriving sexp]
include BitMaskSet.S with type elt := elt
with type storage = int
- with type t = private int \ No newline at end of file
+ with type t = private int
+
+val sexp_of_t : t -> Sexplib.Sexp.t
+val t_of_sexp : Sexplib.Sexp.t -> t
+val of_yojson_exn : Yojson.Safe.t -> t
+val of_yojson : Yojson.Safe.t -> (t, string) result
+val to_yojson : t -> Yojson.Safe.t \ No newline at end of file