I want to sort a vector of objects with a given trait. So I tried adding 'Ord' to the trait. However this produces error E0038, that the trait cannot be made into an object because the use of Self as a type parameter.
Here I want to sort the elements of the disjunction and remove repeated ones in order to have a good normal form. Each regular expression is composed of more of them, as a tree, ending with literals of type T.
This together with the fact that I should compare types (so that EmptyString elements are before Disjunction ones and similiar for others) makes me think that this approach is flawed.
I have rewritten it as enum and now it compiles correctly and the code feels better. Even if there is solution to the the problem; using enums seems much better for my use case than my original idea.
Yeah, trait objects and things like Ord don’t go well together. I see you’ve switched to enums but if you were interested in sorting a vector, you can use sort_by (and friends) to sort via just the public trait object interface and leave the underlying impls alone.