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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
pub(crate) mod groups;
pub mod handle;
mod set;
use handle::GroupHandle;
pub use set::GroupSet;
use uuid::Uuid;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize),
serde(transparent)
)]
pub struct GroupId {
uuid: Uuid,
}
impl GroupId {
pub(crate) fn new() -> Self {
Self {
uuid: Uuid::new_v4(),
}
}
}
impl From<&GroupHandle> for GroupId {
fn from(handle: &GroupHandle) -> Self {
handle.id()
}
}
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize),
serde(default)
)]
pub struct GroupSettings {
pub id: Option<GroupId>,
pub groups: GroupSet,
}
impl GroupSettings {
pub fn new() -> Self {
Self::default()
}
pub fn id(self, id: impl Into<GroupId>) -> Self {
Self {
id: Some(id.into()),
..Default::default()
}
}
pub fn groups(self, groups: impl Into<GroupSet>) -> Self {
Self {
groups: groups.into(),
..Default::default()
}
}
}
impl Default for GroupSettings {
fn default() -> Self {
Self {
id: None,
groups: GroupSet::new(),
}
}
}
#[derive(Debug, Clone)]
pub(crate) struct Group {
groups: GroupSet,
}
impl Group {
pub fn new(settings: GroupSettings) -> Self {
Self {
groups: settings.groups,
}
}
pub fn groups(&self) -> &GroupSet {
&self.groups
}
}