From 12d23e22839d145db49a07d60ba3c9cccf343cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 24 Sep 2022 19:11:22 +0200 Subject: [PATCH] room: clippy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/room.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/room.rs b/src/room.rs index ac8830d..35440e5 100644 --- a/src/room.rs +++ b/src/room.rs @@ -36,7 +36,7 @@ use xmpp_parsers::{ pub type Nick = String; type Session = FullJid; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum BroadcastPresence { /// Resource joined the room. It needs to know about all other participants, and other /// participants needs to know about it. @@ -74,7 +74,7 @@ impl Room { own_session: &Session, mode: BroadcastPresence, ) -> Result<(), Error> { - let leave = mode == BroadcastPresence::Leave; + let leave = matches!(mode, BroadcastPresence::Leave); // All participants to new participant let presence_to_new = Presence::new(if leave { @@ -105,14 +105,8 @@ impl Room { } .into()]); - let sync = match mode { - BroadcastPresence::Join | BroadcastPresence::Resync => true, - _ => false, - }; - let update = match mode { - BroadcastPresence::Join | BroadcastPresence::Update => true, - _ => false, - }; + let sync = matches!(mode, BroadcastPresence::Join | BroadcastPresence::Resync); + let update = matches!(mode, BroadcastPresence::Join | BroadcastPresence::Update); for (_, other) in self.occupants.iter() { if own_occupant.nick == other.nick { @@ -245,7 +239,7 @@ impl Room { new_nick: Nick, ) -> Result<(), Error> { // Ensure nick isn't already assigned - let _ = self.occupants.iter().try_for_each(|(nick, occupant)| { + self.occupants.iter().try_for_each(|(nick, occupant)| { let new_nick = new_nick.as_str(); if new_nick == nick && occupant.real != BareJid::from(realjid.clone()) { return Err(Error::NickAlreadyAssigned(String::from(new_nick))); @@ -268,20 +262,20 @@ impl Room { if !self.occupants.contains_key(&new_nick) { let _ = self.occupants.insert( new_nick.clone(), - Occupant::new(&self, realjid.clone(), new_nick.clone()), + Occupant::new(self, realjid.clone(), new_nick.clone()), ); } let occupant = self.occupants.get(&new_nick).unwrap(); match mode { Some(BroadcastPresence::Resync) => { - self.broadcast_presence(component, &occupant, &realjid, BroadcastPresence::Resync) + self.broadcast_presence(component, occupant, &realjid, BroadcastPresence::Resync) .await?; } Some(BroadcastPresence::Join) => { debug!("{} is joining {}", realjid, self.jid); - self.broadcast_presence(component, &occupant, &realjid, BroadcastPresence::Join) + self.broadcast_presence(component, occupant, &realjid, BroadcastPresence::Join) .await?; self.send_subject(component, realjid, occupant.clone()) .await?; @@ -316,7 +310,7 @@ impl Room { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Occupant { /// Public Jid for the Occupant pub real: BareJid, @@ -339,7 +333,7 @@ impl Occupant { if BareJid::from(real.clone()) != self.real { return Err(Error::MismatchJids( Jid::from(self.real.clone()), - Jid::from(real.clone()), + Jid::from(real), )); }