Is there a way to implement a trait for all types that implement another trait? I want a special Clone-like trait for internal use in my library, call it CloneSpecial. I would like to automatically implement it with Clone for all types that implement Clone, but to make some types that implement CloneSpecial but not Clone. Below is code analogous to my attempt at making this happen:
trait CloneSpecial {
fn clone_special(&self) -> &Self;
}
impl<ClonableType: Clone> CloneSpecial for ClonableType {
fn clone_special(&self) -> &Self {
self.clone() // Error at this line
}
}
The error is as follows:
mismatched types
expected reference, found type parameter
note: expected type
&ClonableType
found typeClonableType
help: type parameters must be constrained to match other types
note: for more information, visit Traits: Defining Shared Behavior - The Rust Programming Language
Is what I'm attempting to do possible? If so, where am I going wrong? Thanks in advance