I'm attempting to write a library that allows the implementor to add a single instance of an arbitrary type to a list of similar type instances. I would like for the implementor to be able to retrieve this instance by type. For example: list_of_types.get::<MyType>()
.
I have achieved this with an AnyMap
, but the next thing I want to do is give the implementor the ability to define a list of types that can be looped through and used to access elements of this AnyMap
. Does Rust have a way to store types themselves rather than instances? Does it change anything if these arbitrary types implement the same trait? Is there a better way to handle a list accessible by element type?