pub struct GenericId<T>(pub i64, pub PhantomData<T>);
pub struct PhantomMyId;
pub type MyId = GenericId<PhantomMyId>;
pub struct PhantomOtherId;
pub type OtherId = GenericId<PhantomOtherId>;
pub fn foo(my_id: &MyId){
}- It is type-safe;
MyId!=OtherId. - The delegate is transparent — no additional effort is required to call the delegate’s methods.
- You can use
deriveor thederive_morecrate.
The method described above is the shortest approach I've found to provide default trait implementations for many child types.