Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions rar-common/src/database/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ impl fmt::Display for SGroupType {
}

impl SGroupType {
pub fn fetch_eq(&self, other: &Self) -> bool {
let uid = self.fetch_id();
let ouid = other.fetch_id();
match (uid, ouid) {
(Some(uid), Some(ouid)) => uid == ouid,
_ => false,
}
}
pub(super) fn fetch_id(&self) -> Option<u32> {
match &self.0 {
SGenericActorType::Id(id) => Some(*id),
Expand Down Expand Up @@ -110,6 +118,16 @@ impl SGroups {
pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn fetch_eq(&self, other: &Self) -> bool {
match (self, other) {
(SGroups::Single(group), SGroups::Single(ogroup)) => group.fetch_eq(ogroup),
(SGroups::Multiple(groups), SGroups::Multiple(ogroups)) => groups
.iter()
.all(|group| ogroups.iter().any(|ogroup| group.fetch_eq(ogroup))),
_ => false,
}
}
}

impl<'de> Deserialize<'de> for SGenericActorType {
Expand Down Expand Up @@ -481,4 +499,12 @@ mod tests {
let groups = SGroups::Multiple(vec![]);
assert!(groups.is_empty());
}

#[test]
fn test_fetch_eq_sgroupstype_false() {
let group1 = SGroupType::from("unkown");
let group2 = SGroupType::from("unkown2");

assert!(!group1.fetch_eq(&group2));
}
}
Loading
Loading