This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Description
The objekt
crate provides a type-safe way to make trait objects clonable, but there are one too many steps involved.
- Use
objekt::Clone
instead of plain Clone
in the supertrait list;
- Call
clone_trait_object!
macro.
trait MyTrait: objekt::Clone {
/* ... */
}
clone_trait_object!(MyTrait);
// Now data structures containing Box<MyTrait> can derive Clone.
#[derive(Clone)]
struct Container {
trait_object: Box<MyTrait>,
}
Ideally this would be taken care of by an attribute macro in one step that expands to the two steps above.
#[clonable]
trait MyTrait: Clone {
/* ... */
}
The attribute macro would assert that Clone
is present in the supertrait list (or else fail to compile with an error), substitute that Clone
with objekt::Clone
, and then make the correct call to clone_trait_object!
to emit the trait object impl.