Browse Source

Clippy and rustfmt.

Jing Yang 5 năm trước cách đây
mục cha
commit
39f00e7083
2 tập tin đã thay đổi với 10 bổ sung9 xóa
  1. 8 8
      src/network.rs
  2. 2 1
      src/server.rs

+ 8 - 8
src/network.rs

@@ -75,9 +75,9 @@ impl Network {
         client: C,
         yes: bool,
     ) {
-        self.clients
-            .get_mut(client.as_ref())
-            .map(|pair| pair.0 = yes);
+        if let Some(pair) = self.clients.get_mut(client.as_ref()) {
+            pair.0 = yes;
+        }
     }
 
     pub fn add_server<S: Into<ServerIdentifier>>(
@@ -101,6 +101,7 @@ impl Network {
             .map(|s| s.rpc_count())
     }
 
+    #[allow(clippy::ptr_arg)]
     fn dispatch(&self, client: &ClientIdentifier) -> Result<Arc<Server>> {
         let (enabled, server_name) =
             self.clients.get(client).ok_or_else(|| {
@@ -334,7 +335,7 @@ impl Network {
 
 #[cfg(test)]
 mod tests {
-    use std::sync::{MutexGuard, Barrier};
+    use std::sync::{Barrier, MutexGuard};
 
     use crate::test_utils::{
         junk_server::{
@@ -559,9 +560,8 @@ mod tests {
             let network_ref = network.clone();
             let barrier_ref = barrier.clone();
             let handle = std::thread::spawn(move || {
-                let client = unlock(&network_ref).make_client(
-                    format!("{}-{}", TEST_CLIENT, i), TEST_SERVER
-                );
+                let client = unlock(&network_ref)
+                    .make_client(format!("{}-{}", TEST_CLIENT, i), TEST_SERVER);
                 // We should all create the client first.
                 barrier_ref.wait();
 
@@ -569,7 +569,7 @@ mod tests {
                 for _ in 0..RPC_COUNT {
                     let reply = client.call_rpc(
                         JunkRpcs::Echo.name(),
-                        RequestMessage::from_static(&[0x20, 0x17])
+                        RequestMessage::from_static(&[0x20, 0x17]),
                     );
                     results.push(reply);
                 }

+ 2 - 1
src/server.rs

@@ -43,7 +43,7 @@ impl Server {
                     .lock()
                     .expect("The server state mutex should not be poisoned");
                 state.rpc_count.set(state.rpc_count.get() + 1);
-                state.rpc_handlers.get(&service_method).map(|r| r.clone())
+                state.rpc_handlers.get(&service_method).cloned()
             };
             let response = match rpc_handler {
                 Some(rpc_handler) => Ok(rpc_handler.call(data)),
@@ -55,6 +55,7 @@ impl Server {
                     ),
                 )),
             };
+            #[allow(clippy::redundant_pattern_matching)]
             if let Err(_) = tx.send(response) {
                 // Receiving end is dropped. Never mind.
                 // Do nothing.