When you can't create a trait object due to a trait not being object safe, you have a few options:
- if you control the trait, try to make it object safe (medium difficulty)
- if you don't control the trait, try to get the upstream owner to make it object safe or find an alternative (hard)
- if the set of types you're trying to trait-objectify is closed, use an enum (easy)
Unfortunately, the error message for a trait not being object safe doesn't point you in the direction of the enum option, and unless you're pretty familiar with Rust you may not consider it.
Adjusting the error message for failure to create a trait object due to object safety issues to mention an enum as a possibility could help people resolve these issues. I have no data, but in my experience the enum path is often workable because I'm working with a finite set of variants that I know in advance.
When you can't create a trait object due to a trait not being object safe, you have a few options:
Unfortunately, the error message for a trait not being object safe doesn't point you in the direction of the enum option, and unless you're pretty familiar with Rust you may not consider it.
Adjusting the error message for failure to create a trait object due to object safety issues to mention an enum as a possibility could help people resolve these issues. I have no data, but in my experience the enum path is often workable because I'm working with a finite set of variants that I know in advance.