Skip to content

Commit 02ab347

Browse files
d-e-s-oryzhyk
authored andcommitted
Properly implement Clone for SharedObserver
When using an auto derive to implement a trait such as Clone on a generic object, the code emitted will contain a constraint like: T: Clone. That is a problem for our SharedObserver, because our inner Observer does not implement Clone, and that is fine and desired. In order to work around this problem (known upstream as [issue 64417][]) we need to implement Clone for SharedObserver manually. [issue 64417]: rust-lang/rust#64417
1 parent a49c00b commit 02ab347

File tree

1 file changed

+7
-1
lines changed
  • rust/template/distributed_datalog/observe/src

1 file changed

+7
-1
lines changed

rust/template/distributed_datalog/observe/src/observer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where
3131

3232
/// Wrapper around an `Observer` that allows for it to be shared by
3333
/// wrapping it into a combination of `Arc` & `Mutex`.
34-
#[derive(Debug, Clone)]
34+
#[derive(Debug)]
3535
pub struct SharedObserver<O>(pub Arc<Mutex<O>>);
3636

3737
impl<O> SharedObserver<O> {
@@ -42,6 +42,12 @@ impl<O> SharedObserver<O> {
4242
}
4343
}
4444

45+
impl<O> Clone for SharedObserver<O> {
46+
fn clone(&self) -> Self {
47+
SharedObserver(self.0.clone())
48+
}
49+
}
50+
4551
impl<O, T, E> Observer<T, E> for SharedObserver<O>
4652
where
4753
O: Observer<T, E>,

0 commit comments

Comments
 (0)