I would like to create a container for a mapping from keys that have an implicit associated value type
T to objects of type
Vec<T>. I have successfully created such a container for a mapping of such keys to objects of type
So, to be specific, I would like to create a struct with methods like:
set_value<K: Key>(&mut self, index: usize, value: K::Value)
get_value<K: Key>(&self, index: usize) -> Option<&K::Value>
that would set/get values in slot ‘index’ of the associated
Vec<K::Value> (assuming such a slot exists).
I’d also appreciate any suggestions for making this more idiomatic if the construction I’m proposing is not ideal. Thank you!
Edit: Further information - I have tried variations on what I assumed would be the natural extension from the gist above - to replace the map in Container with a
HashMap<TypeId, Vec<_>> and trying various things in place of
_. But, none of the things I have considered and attempted work (generally they won’t compile). I explicitly do not want to use a
Boxed type inside of the
Vec because of the overhead cost (this could have hundreds of millions of indexes, for example).