Idiomatic way to have a function associated to a string

it is a common thing (for example when using clap or rustyline) to have to call a function according to a determined user input / command (a String or &str).

I don't particularly like to have a huge match statement (especially when you have several commands) so I was thinking what is the idiomatic way to do this. The other option on my table is a static HashMap mapping the String to the function.

Any better idea or crate?

I'd say match is the idiomatic way.

Also you probably want clap to parse the command string into an enum and match on that instead of strings.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.