I have implemented a struct that can stored any data using the Any trait passed as parameters (storing) and returns (retrieving). All move actions, as storing takes ownership of the data. Everything works nicely and in the expected manner, downcasting to get the actual data back to manipulate.
However I would like to restrict the types of data that can be stored in the struct, perhaps by using a marker trait to tag the data, and thus only data that implements the marker trait is allowed to be stored in the struct. I could make the marker trait extend the Any trait, though run into the issue of downcasting when retrieving the data from the struct to obtain the actual data type that implements the marker. That is the downcast is not supported for the data marker trait, even though data marker extends the Any trait.
So makes me wonder.
Is it possible to restrict the types allowed for Any trait using a marker trait, or some other means? And still be able to downcast to the actual data type, to manipulate the fields (or by methods) of the data type, by code that knows of the data type in question.