rust - Converting to a Box<Any> -


I have the box & lt; Specialty & gt; , and want to be able to put it on the box < Obj & gt; . It is believed that this is to be done, but t.downcast :: & lt; Obj & gt; Attempting to call () says that there is no downcast in the method.

The docs shows how to do this: If you have a reference you can just & amp; As a specialty & amp; Anyone can . boxedTrait as box & lt; Any & gt; It is not possible to .

It shows what I mean.

allows any downtake of a concrete type, so you Required to know the concrete type when you press the box & lt; Any & gt; However, you do not know the concrete type if you have only one attribute item for some other attribute - this particular property is the point of the objects then you can see the box & lt; SomeTrait & gt; to box & lt; Any & gt; , it is impossible.

Ideally it is possible to write something like box & lt; Show + any & gt; It will also allow the use of any methods with the show methods, it is also impossible, though: you only have additional life styles for the main feature and You can type in the underlying type, so the box & lt; Show + Sync + 'a & gt; is legal, but box & lt; <+ Show any .

If you want to use it with any , then one way to get it will be the property:

  trait MyTrait: Someone Also {// ...}  

However, inheritance properties do not work with objects, so you can not call on matches Box & lt; MyTrait & gt; Includes reworking of any (as can be found), but it is pretty much anything.

Unfortunately, I'm not aware of a simple way to talk about this kind of thing possibly possible to implement with some unsafe code, but I do not know how.


Comments