From 3df447de97f2b47224194558ab4812fc68acecd0 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 10 Dec 2020 20:28:32 +0100 Subject: [PATCH] jid: Implement PartialEq between Jid and BareJid/FullJid. This can be useful at times. --- jid/src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/jid/src/lib.rs b/jid/src/lib.rs index aa9e294b..dd5f734a 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -149,6 +149,42 @@ impl TryFrom for FullJid { } } +impl PartialEq for FullJid { + fn eq(&self, other: &Jid) -> bool { + match other { + Jid::Full(full) => self == full, + Jid::Bare(_) => false, + } + } +} + +impl PartialEq for BareJid { + fn eq(&self, other: &Jid) -> bool { + match other { + Jid::Full(_) => false, + Jid::Bare(bare) => self == bare, + } + } +} + +impl PartialEq for Jid { + fn eq(&self, other: &FullJid) -> bool { + match self { + Jid::Full(full) => full == other, + Jid::Bare(_) => false, + } + } +} + +impl PartialEq for Jid { + fn eq(&self, other: &BareJid) -> bool { + match self { + Jid::Full(_) => false, + Jid::Bare(bare) => bare == other, + } + } +} + /// A struct representing a full Jabber ID. /// /// A full Jabber ID is composed of 3 components, of which one is optional: