From 6d67cd2ac72a9a72a1664f28df9df48aa95019cd Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 27 Apr 2020 12:12:51 +0200 Subject: [PATCH] Fix clippy lints --- src/base_client.rs | 2 +- src/models/room.rs | 7 +++---- src/test_builder.rs | 12 ++++++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/base_client.rs b/src/base_client.rs index d79e94dc..b3e2f913 100644 --- a/src/base_client.rs +++ b/src/base_client.rs @@ -168,7 +168,7 @@ impl Client { pub(crate) async fn calculate_room_names(&self) -> Vec { let mut res = Vec::new(); - for (_id, room) in &self.joined_rooms { + for room in self.joined_rooms.values() { let room = room.read().await; res.push(room.room_name.calculate_name(&room.members)) } diff --git a/src/models/room.rs b/src/models/room.rs index a7f04230..e96f8f1d 100644 --- a/src/models/room.rs +++ b/src/models/room.rs @@ -166,8 +166,7 @@ impl RoomName { .map(|mem| { mem.display_name .clone() - .unwrap_or(mem.user_id.localpart().to_string()) - .to_string() + .unwrap_or_else(|| mem.user_id.localpart().to_string()) }) .collect::>(); // stabilize ordering @@ -180,7 +179,7 @@ impl RoomName { .map(|mem| { mem.display_name .clone() - .unwrap_or(mem.user_id.localpart().to_string()) + .unwrap_or_else(|| mem.user_id.localpart().to_string()) }) .collect::>(); names.sort(); @@ -502,7 +501,7 @@ mod test { .await; assert_eq!(2, room.members.len()); - for (_id, member) in &room.members { + for member in room.members.values() { assert_eq!(MembershipState::Join, member.membership); } diff --git a/src/test_builder.rs b/src/test_builder.rs index 43ac5e0b..75984a66 100644 --- a/src/test_builder.rs +++ b/src/test_builder.rs @@ -96,7 +96,7 @@ impl EventBuilder { variant: fn(Ev) -> Event, ) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -112,7 +112,7 @@ impl EventBuilder { variant: fn(Ev) -> Event, ) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -128,7 +128,7 @@ impl EventBuilder { variant: fn(Ev) -> RoomEvent, ) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -144,7 +144,7 @@ impl EventBuilder { variant: fn(Ev) -> StateEvent, ) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -156,7 +156,7 @@ impl EventBuilder { /// Add a presence event to the presence events `Vec`. pub fn add_presence_event_from_file>(mut self, path: P) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -174,7 +174,7 @@ impl EventBuilder { P: AsRef, { let body = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let mock = Some( mock(method, matcher) .with_status(200)