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
use std::fmt;

use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::message::Message;

// deriving also Copy here is a bit on the expensive side, but makes life easier
#[derive(Clone, Copy, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub struct UUID {
  #[serde(with = "uuid::serde::compact")] // straightforward binary serialization, not text
  pub uuid: Uuid,
}
impl Message for UUID {}

impl fmt::Debug for UUID {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    fmt::Display::fmt(self.uuid.as_simple(), f)
  }
}

impl UUID {
  pub const ZERO: UUID = UUID { uuid: Uuid::nil() };

  pub fn new_random() -> Self {
    UUID {
      uuid: Uuid::new_v4(),
    }
  }
}

// #[cfg(test)]
// mod tests {

//   #[test]
//   fn test_serialize() {
//     let
//   }

// }