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
44
45
46
47
48
49
50
51
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(
Clone,
Debug,
PartialEq,
Eq,
Hash,
Archive,
RkyvSerialize,
RkyvDeserialize,
Serialize,
Deserialize,
)]
#[repr(transparent)]
pub struct UuidV4([u8; 16]);
impl UuidV4 {
pub fn new_v4() -> Self {
UuidV4(*Uuid::new_v4().as_bytes())
}
pub fn as_uuid(&self) -> Uuid {
Uuid::from_bytes(self.0)
}
}
impl From<Uuid> for UuidV4 {
fn from(u: Uuid) -> Self {
UuidV4(*u.as_bytes())
}
}
impl From<UuidV4> for Uuid {
fn from(v: UuidV4) -> Self {
Uuid::from_bytes(v.0)
}
}
impl Default for UuidV4 {
fn default() -> Self {
UuidV4([0u8; 16])
}
}