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
derive
or thederive_more
crate.