I am writing a program which accepts a numerical type on the command line, and then calls a generic function using that type. For example, I run program thus:
my_programme u32
...and in my code I have:
match cli_type
{
"u32" =>
{
my_generic_function::<u32>(args);
},
"u16" =>
...
If I want to do this for 8, 16, 32, and 64 bit integers, both signed and unsigned, that's a lot of calls to my_generic_function(). It looks messy and seems needless.
Can I define a map between &str or String values and type T, or write a function to return type T, so instead of the match statement, I could just write:
my_generic_function::<get_type(cli_type)>(args);