I want create two generic implementation if i have one trait and i create one impl else i create another impl. For example:
trait Abc;
trait Ab;
impl<T: Abc> Ab for T {...}
impl<T: not_have Abc> Ab for T {...}
I want create two generic implementation if i have one trait and i create one impl else i create another impl. For example:
trait Abc;
trait Ab;
impl<T: Abc> Ab for T {...}
impl<T: not_have Abc> Ab for T {...}
This is not currently possible in stable Rust. It requires specialization, which is still under development.
When approximately will it be released?
There's no ETA but if I had to take a guess it will take years. Specialization has been historically very tricky to implement due to soundness issues, and right now even the nightly feature is very buggy and in a semi-abandoned state.
This particular feature in some form is possible without full specialization, but is still so far away the practical answer is "figure out something else".
Namely, if Rust gets negative trait bounds, it will almost surely mean "the type has explicitly opted out of implementing this trait" and not "the type hasn't happened to implement this trait yet".[1] Otherwise adding implementations would be a major breaking change.
So in this form, your two implementations wouldn't cover every type, just those that opted into or out of the trait in the bound.
But again, too distant of a possibility to be excited about today.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.