Given some type, such as String
, is it possible to store the Type in a collection such as a HashMap
for the purpose of retrieving it later to create a new instance of String
?
Something like:
let string = String::type;
let mut types = HashMap::<String, Type>::new();
types.insert("string", string);
// ... in another place of the code
let string: String = types.get("string")?::new();
For reference, I'm thinking about this in terms of a dependency injection framework and what that might look like in a Rust world. I haven't taken a look at Crates yet to avoid spoilers