Skip to content

Commit

Permalink
Properly implement Clone for SharedObserver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
d-e-s-o authored and ryzhyk committed Oct 22, 2019
1 parent a49c00b commit 02ab347
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rust/template/distributed_datalog/observe/src/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ where

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

impl<O> SharedObserver<O> {
Expand All @@ -42,6 +42,12 @@ impl<O> SharedObserver<O> {
}
}

impl<O> Clone for SharedObserver<O> {
fn clone(&self) -> Self {
SharedObserver(self.0.clone())
}
}

impl<O, T, E> Observer<T, E> for SharedObserver<O>
where
O: Observer<T, E>,
Expand Down

0 comments on commit 02ab347

Please sign in to comment.