Sized-specific implementation?

Is that possible to have several implementations of a trait, one for T:Sized another one for T:Unsized?


Seems it is not possible without specialization.

Not that I know of. Both specialization and negative trait bounds are currently unstable. Specialization is unsound, min_specialization may be sound and I believe negative trait bounds are unsound too. You can have one implementation for T:Sized and one for each individual unsized type though. So impl<T> Trait1<T> for T {} and then impl<T> Trait1<[T]> for [T] {}, impl Trait1<dyn SomeTrait> for dyn SomeTrait {}, impl Trait1<dyn SomeOtherTrait> for dyn SomeOtherTrait {}, ...


Sounds reasonable. Thanks!

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.