You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not super experienced with dynamic dispatch, so there may be a better approach to solve this problem—feel free to point me in the right direction.
I want to have an enum translate to a lazy_static singleton. This is the classic example of something that wants to be const but requires allocation. However, I have two different types that I want the enum to translate to. To enable this, I wrapped the type in a Box<dyn Trait>. However, that doesn't appear to work with lazy_static.
Is there a way to resolve this situation? Here's an example of the kind of thing I'm trying to do:
The error you are getting is because all statics created with lazy_static have to be Send and Sync. If you change Box<dyn Trait + Send + Sync>, it works. (I had to change another unrelated problem, but nevermind.)
Apart from that: do you need to return Box<_> from to_lazy_box? Are you sure? If not, you could just make the statics have the type Box<StructA> (and B and C) and return a &dyn Trait from to_lazy_box.
And I do understand you correctly that this is a question rather than a feature request, right?
I'm not super experienced with dynamic dispatch, so there may be a better approach to solve this problem—feel free to point me in the right direction.
I want to have an
enum
translate to alazy_static
singleton. This is the classic example of something that wants to beconst
but requires allocation. However, I have two different types that I want theenum
to translate to. To enable this, I wrapped the type in aBox<dyn Trait>
. However, that doesn't appear to work withlazy_static
.Is there a way to resolve this situation? Here's an example of the kind of thing I'm trying to do:
The text was updated successfully, but these errors were encountered: