ソースを参照

Lots of clippy changes.

Jing Yang 5 年 前
コミット
3c225e7891
3 ファイル変更15 行追加17 行削除
  1. 9 11
      src/lib.rs
  2. 3 3
      src/rpcs.rs
  3. 3 3
      src/utils.rs

+ 9 - 11
src/lib.rs

@@ -34,10 +34,10 @@ struct Term(usize);
 #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
 struct Peer(usize);
 
-#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize, Deserialize)]
 pub struct Command(usize);
 
-#[derive(Clone, Copy, Serialize, Deserialize)]
+#[derive(Clone, Serialize, Deserialize)]
 struct LogEntry {
     term: Term,
     index: usize,
@@ -121,7 +121,7 @@ impl Raft {
         apply_command: Func,
     ) -> Self
     where
-        Func: 'static + Send + FnMut(usize, Command) -> (),
+        Func: 'static + Send + FnMut(usize, Command),
     {
         let peer_size = peers.len();
         let state = RaftState {
@@ -434,7 +434,7 @@ impl Raft {
         if let Ok(reply) = reply {
             return Some(reply.vote_granted && reply.term == term);
         }
-        return None;
+        None
     }
 
     async fn count_vote_util_cancelled(
@@ -564,11 +564,11 @@ impl Raft {
 
     fn run_log_entry_daemon(&mut self) -> std::thread::JoinHandle<()> {
         let (tx, rx) = std::sync::mpsc::channel::<Option<Peer>>();
-        self.new_log_entry.replace(tx.clone());
+        self.new_log_entry.replace(tx);
 
         // Clone everything that the thread needs.
         let this = self.clone();
-        let handle = std::thread::spawn(move || {
+        std::thread::spawn(move || {
             while let Ok(peer) = rx.recv() {
                 if !this.keep_running.load(Ordering::SeqCst) {
                     break;
@@ -586,9 +586,7 @@ impl Raft {
                     }
                 }
             }
-        });
-
-        handle
+        })
     }
 
     async fn sync_log_entry(
@@ -696,7 +694,7 @@ impl Raft {
         mut apply_command: Func,
     ) -> std::thread::JoinHandle<()>
     where
-        Func: 'static + Send + FnMut(usize, Command) -> (),
+        Func: 'static + Send + FnMut(usize, Command),
     {
         let keep_running = self.keep_running.clone();
         let rf = self.inner_state.clone();
@@ -716,7 +714,7 @@ impl Raft {
                         let index = rf.last_applied;
                         let commands: Vec<Command> = rf.log[index..]
                             .iter()
-                            .map(|entry| entry.command)
+                            .map(|entry| entry.command.clone())
                             .collect();
                         (index, commands)
                     } else {

+ 3 - 3
src/rpcs.rs

@@ -40,8 +40,8 @@ impl RpcHandler for AppendEntriesRpcHandler {
     }
 }
 
-pub(crate) const REQUEST_VOTE_RPC: &'static str = "Raft.RequestVote";
-pub(crate) const APPEND_ENTRIES_RPC: &'static str = "Raft.AppendEntries";
+pub(crate) const REQUEST_VOTE_RPC: &str = "Raft.RequestVote";
+pub(crate) const APPEND_ENTRIES_RPC: &str = "Raft.AppendEntries";
 
 #[derive(Clone)]
 pub struct RpcClient(Client);
@@ -95,7 +95,7 @@ pub(crate) fn register_server<S: AsRef<str>>(
         Box::new(request_vote_rpc_handler),
     )?;
 
-    let append_entries_rpc_handler = AppendEntriesRpcHandler(raft.clone());
+    let append_entries_rpc_handler = AppendEntriesRpcHandler(raft);
     server.register_rpc_handler(
         APPEND_ENTRIES_RPC.to_owned(),
         Box::new(append_entries_rpc_handler),

+ 3 - 3
src/utils.rs

@@ -21,17 +21,17 @@ where
     ))
 }
 
-pub struct DropGuard<F: FnOnce() -> ()> {
+pub struct DropGuard<F: FnOnce()> {
     task: Option<F>,
 }
 
-impl<F: FnOnce() -> ()> DropGuard<F> {
+impl<F: FnOnce()> DropGuard<F> {
     pub fn new(task: F) -> Self {
         Self { task: Some(task) }
     }
 }
 
-impl<F: FnOnce() -> ()> Drop for DropGuard<F> {
+impl<F: FnOnce()> Drop for DropGuard<F> {
     fn drop(&mut self) {
         (self.task.take().unwrap())();
     }