Skip to content

Commit d84d3be

Browse files
authored
Merge pull request #67 from hocineait7/main
Add group option
2 parents 31f3ef1 + 9929cf1 commit d84d3be

File tree

8 files changed

+1199
-37
lines changed

8 files changed

+1199
-37
lines changed

rar-common/src/database/actor.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ impl fmt::Display for SGroupType {
6767
}
6868

6969
impl SGroupType {
70+
pub fn fetch_eq(&self, other: &Self) -> bool {
71+
let uid = self.fetch_id();
72+
let ouid = other.fetch_id();
73+
match (uid, ouid) {
74+
(Some(uid), Some(ouid)) => uid == ouid,
75+
_ => false,
76+
}
77+
}
7078
pub(super) fn fetch_id(&self) -> Option<u32> {
7179
match &self.0 {
7280
SGenericActorType::Id(id) => Some(*id),
@@ -110,6 +118,16 @@ impl SGroups {
110118
pub fn is_empty(&self) -> bool {
111119
self.len() == 0
112120
}
121+
122+
pub fn fetch_eq(&self, other: &Self) -> bool {
123+
match (self, other) {
124+
(SGroups::Single(group), SGroups::Single(ogroup)) => group.fetch_eq(ogroup),
125+
(SGroups::Multiple(groups), SGroups::Multiple(ogroups)) => groups
126+
.iter()
127+
.all(|group| ogroups.iter().any(|ogroup| group.fetch_eq(ogroup))),
128+
_ => false,
129+
}
130+
}
113131
}
114132

115133
impl<'de> Deserialize<'de> for SGenericActorType {
@@ -481,4 +499,12 @@ mod tests {
481499
let groups = SGroups::Multiple(vec![]);
482500
assert!(groups.is_empty());
483501
}
502+
503+
#[test]
504+
fn test_fetch_eq_sgroupstype_false() {
505+
let group1 = SGroupType::from("unkown");
506+
let group2 = SGroupType::from("unkown2");
507+
508+
assert!(!group1.fetch_eq(&group2));
509+
}
484510
}

0 commit comments

Comments
 (0)