1use derive_more::Display;
8use serde::{Deserialize, Serialize};
9
10pub trait PaperlessId:
12 std::fmt::Display + PartialEq + Eq + std::hash::Hash + serde::de::DeserializeOwned + Serialize
13{
14}
15
16macro_rules! define_ids {
18 ($($def:tt),* $(,)?) => {
19 $(define_ids!(@single $def);)*
20 };
21
22 (@single ($name:ident, $type:ty)) => {
23 #[derive(Clone, Copy, Display, Default, PartialEq, Eq, Hash, Deserialize, Serialize)]
24 #[repr(transparent)]
25 pub struct $name(pub $type);
26
27 impl std::fmt::Debug for $name {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 write!(f, "{}({})", stringify!($name), *self)
30 }
31 }
32
33 impl std::ops::Deref for $name {
34 type Target = $type;
35
36 fn deref(&self) -> &Self::Target {
37 &self.0
38 }
39 }
40
41 impl PaperlessId for $name {}
42 };
43 (@single ($name:ident, $type:ty, noncopy)) => {
44 #[derive(Clone, Display, Default, PartialEq, Eq, Hash, Deserialize, Serialize)]
45 #[repr(transparent)]
46 pub struct $name(pub $type);
47
48 impl std::fmt::Debug for $name {
49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 write!(f, "{}({})", stringify!($name), *self)
51 }
52 }
53
54 impl std::ops::Deref for $name {
55 type Target = $type;
56
57 fn deref(&self) -> &Self::Target {
58 &self.0
59 }
60 }
61
62 impl PaperlessId for $name {}
63 };
64}
65
66define_ids!(
67 (CorrespondentId, u32),
68 (CustomFieldId, u32),
69 (DocumentId, u32),
70 (DocumentTypeId, u32),
71 (GroupId, u32),
72 (NoteId, u32),
73 (SavedViewId, u32),
74 (SelectableOptionId, String, noncopy),
75 (ShareLinkId, u32),
76 (StoragePathId, u32),
77 (TagId, u32),
78 (TaskId, String, noncopy),
79 (UserId, u32),
80 (WorkflowActionId, u32),
81 (WorkflowId, u32),
82 (WorkflowTriggerId, u32),
83 (WebhookActionId, u32),
84);