Since https://github.com/mcarton/rust-derivative is not under maintenance.
I found this https://github.com/ModProg/derive-where
use derive_where::derive_where;
use std::sync::Arc;
struct Unclonable {}
struct A<T>(Arc<T>);
impl<T> Clone for A<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
#[derive_where(Clone)]
struct B<T>(Arc<T>);
fn main() {
let a = A(Arc::new(Unclonable {}));
let b = B(Arc::new(Unclonable {}));
// Works
a.clone();
// Works
b.clone();
}
Another crate also works: https://github.com/magiclen/educe
This is the Github issue about this question: https://github.com/rust-lang/rust/issues/26925