Prechádzať zdrojové kódy

Make SharedSender clonable for any T.

Jing Yang 3 rokov pred
rodič
commit
13d6273469
2 zmenil súbory, kde vykonal 8 pridanie a 2 odobranie
  1. 1 1
      src/sync_log_entries.rs
  2. 7 1
      src/utils/shared_sender.rs

+ 1 - 1
src/sync_log_entries.rs

@@ -14,7 +14,7 @@ use crate::{
     Peer, Raft, RaftState, RemoteRaft, ReplicableCommand, Term,
 };
 
-#[derive(Clone, Eq, PartialEq)]
+#[derive(Eq, PartialEq)]
 enum Event {
     NewTerm(Term, Index),
     NewLogEntry(Index),

+ 7 - 1
src/utils/shared_sender.rs

@@ -14,7 +14,7 @@
 ///
 /// Note that the same reasoning does not apply to the `Receiver`. There are
 /// more levels of mutability in the `Receiver`.
-#[derive(Clone, Debug)]
+#[derive(Debug)]
 pub struct SharedSender<T>(std::sync::mpsc::Sender<T>);
 
 unsafe impl<T> Sync for SharedSender<T> where T: Sync {}
@@ -48,3 +48,9 @@ impl<T> From<SharedSender<T>> for std::sync::mpsc::Sender<T> {
         this.0
     }
 }
+
+impl<T> Clone for SharedSender<T> {
+    fn clone(&self) -> Self {
+        Self(self.0.clone())
+    }
+}