I'd like to implement my own version of a Rust standard library feature and use my version and the real standard library version interchangeably.
If the standard library feature were a trait, this would be easy. However, the standard library feature (in this case, std::sync::Condvar
) is implemented as
pub struct Condvar {...}
impl Condvar {...}
I tried doing
impl Condvar for MyCondvar {...}
but got an error ("error[E0404]: expected trait, found struct Condvar
")
How should I do this? I've also tried
pub trait CondvarTrait { // copy entire interface of Condvar }
impl CondvarTrait for Condvar {
// copy entire interface of Condvar again,
// implementing foo(&self, ...) by calling self.foo(...)
}
impl CondvarTrait for MyCondvar { // my own implementation }
which compiles, but is super verbose. Is there a better way?