Skip to content

Commit 4f816f8

Browse files
fix: fix clippy warnings
1 parent 002c03c commit 4f816f8

3 files changed

Lines changed: 21 additions & 25 deletions

File tree

src/communication_server.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
use std::collections::{HashMap, HashSet};
23
use crossbeam::channel::{Receiver, Sender};
34
use wg_internal::network::NodeId;
@@ -134,22 +135,22 @@ impl Processor for ChatServer {
134135
NodeCommand::RemoveSender(node_id) => self.routing_handler.remove_neighbor(*node_id),
135136
NodeCommand::Shutdown => return true
136137
}
137-
} else if let Some(cmd) = cmd.downcast_ref::<ChatCommand>() {
138-
if let ChatCommand::GetRegisteredClients = cmd {
139-
let registered_clients = self.get_registered_clients();
140-
if self.controller_send.send(Box::new(ChatEvent::RegisteredClients {
141-
notification_from: self.id,
142-
list: registered_clients
143-
})).is_err() {
144-
return true;
145-
}
138+
} else if let Some(ChatCommand::GetRegisteredClients) = cmd.downcast_ref::<ChatCommand>() {
139+
let registered_clients = self.get_registered_clients();
140+
if self.controller_send.send(Box::new(ChatEvent::RegisteredClients {
141+
notification_from: self.id,
142+
list: registered_clients
143+
})).is_err() {
144+
return true;
146145
}
146+
147147
}
148148
false
149149
}
150150
}
151151

152152
mod communication_server_tests {
153+
#[allow(clippy::wildcard_imports)]
153154
use super::*;
154155
use crossbeam::channel::unbounded;
155156

src/media_server.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ impl Processor for MediaServer {
109109
match Uuid::parse_str(&media_id) {
110110
Ok(uuid) => {
111111
if let Some(media_file) = self.get_media_by_id(uuid) {
112-
if let Ok(serialized_media) = serde_json::to_vec(media_file) {
113-
if let Ok(res) = serde_json::to_vec(&WebResponse::MediaFile {
112+
if let Ok(serialized_media) = serde_json::to_vec(media_file)
113+
&& let Ok(res) = serde_json::to_vec(&WebResponse::MediaFile {
114114
media_data: serialized_media
115115
}) {
116116
let _ = self.routing_handler.send_message(&res, from, Some(session_id));
@@ -122,17 +122,14 @@ impl Processor for MediaServer {
122122
notification_from: self.id,
123123
file: media_id.clone(),
124124
}));
125-
}
126125
}
127-
} else {
128-
if let Ok(res) = serde_json::to_vec(&WebResponse::ErrorFileNotFound(uuid)) {
126+
} else if let Ok(res) = serde_json::to_vec(&WebResponse::ErrorFileNotFound(uuid)) {
129127
let _ = self.routing_handler.send_message(&res, from, Some(session_id));
130128
let _ = self.controller_send.send(Box::new(NodeEvent::MessageSent {
131129
notification_from: self.id,
132130
to: from
133131
}));
134132
}
135-
}
136133
}
137134
Err(_) => {
138135
if let Ok(res) = serde_json::to_vec(&WebResponse::BadUuid(media_id.clone())) {
@@ -178,8 +175,8 @@ impl Processor for MediaServer {
178175
}
179176
}
180177
WebCommand::GetMediaFile{media_id, location: _location} => {
181-
if let Some(media_file) = self.get_media_by_id(*media_id) {
182-
if self.controller_send
178+
if let Some(media_file) = self.get_media_by_id(*media_id)
179+
&& self.controller_send
183180
.send(Box::new(WebEvent::MediaFile {
184181
notification_from: self.id,
185182
file: media_file.clone(),
@@ -188,7 +185,6 @@ impl Processor for MediaServer {
188185
{
189186
return true;
190187
}
191-
}
192188
}
193189
WebCommand::AddMediaFile(media_file) => {
194190
let file_id = media_file.id;

src/text_server.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ impl Processor for TextServer {
122122
}));
123123
match Uuid::parse_str(&file_id) {
124124
Ok(uuid) => {
125-
if let Some(text_file) = self.get_file_by_id(uuid) {
126-
if let Ok(serialized_file) = serde_json::to_vec(text_file) {
125+
if let Some(text_file) = self.get_file_by_id(uuid)
126+
&& let Ok(serialized_file) = serde_json::to_vec(text_file) {
127127
if let Ok(res) = serde_json::to_vec(&WebResponse::TextFile { file_data: serialized_file }) {
128128
let _ = self.routing_handler.send_message(&res, from, Some(session_id));
129129
let _ = self.controller_send.send(Box::new(NodeEvent::MessageSent {
@@ -135,7 +135,6 @@ impl Processor for TextServer {
135135
file: file_id.clone(),
136136
}));
137137
}
138-
}
139138
} else if let Ok(res) = serde_json::to_vec(&WebResponse::ErrorFileNotFound(uuid)) {
140139
let _ = self.routing_handler.send_message(&res, from, Some(session_id));
141140
let _ = self.controller_send.send(Box::new(NodeEvent::MessageSent {
@@ -160,7 +159,7 @@ impl Processor for TextServer {
160159
}
161160
}
162161
}
163-
_ => {}
162+
WebRequest::MediaQuery{ .. } => {}
164163
}
165164
}
166165
}
@@ -188,8 +187,8 @@ impl Processor for TextServer {
188187
}
189188
}
190189
WebCommand::GetTextFile(uuid) => {
191-
if let Some(text_file) = self.get_file_by_id(*uuid) {
192-
if self.controller_send
190+
if let Some(text_file) = self.get_file_by_id(*uuid)
191+
&& self.controller_send
193192
.send(Box::new(WebEvent::TextFile {
194193
notification_from: self.id,
195194
file: text_file.clone(),
@@ -198,7 +197,7 @@ impl Processor for TextServer {
198197
{
199198
return true;
200199
}
201-
}
200+
202201
}
203202
WebCommand::AddTextFile(text_file) => {
204203
let file_id = text_file.id;

0 commit comments

Comments
 (0)