소스 검색

ensure thread safety with types

Justin Tracey 10 달 전
부모
커밋
8de0784cc3
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      src/updater.rs

+ 3 - 3
src/updater.rs

@@ -7,9 +7,9 @@ use tokio::sync::Notify;
 /// Any copy of the owner (created via clone) can send or receive objects,
 /// but only one copy will receive any particular object.
 #[derive(Default)]
-pub struct Updater<T>(Arc<(Mutex<Option<T>>, Notify)>);
+pub struct Updater<T: Send + Sync>(Arc<(Mutex<Option<T>>, Notify)>);
 
-impl<T> Updater<T> {
+impl<T: Send + Sync> Updater<T> {
     /// Send an object T to the receiver end, repacing any currently queued object.
     pub fn send(&self, value: T) {
         let mut locked_object = self.0 .0.lock().expect("send failed to lock mutex");
@@ -46,7 +46,7 @@ impl<T> Updater<T> {
     }
 }
 
-impl<T> Clone for Updater<T> {
+impl<T: Send + Sync> Clone for Updater<T> {
     fn clone(&self) -> Self {
         Updater(Arc::clone(&self.0))
     }