79571732

Date: 2025-04-13 15:59:14
Score: 0.5
Natty:
Report link

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

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Yanni Wang