In fact it does not. You can use it even in C with structures like: gist.github.com/wefhy/4fa3039bac8a...
And additionally you can automatically generate help message from this.
But I also love Rust for things like this ;)
In C/C++ you could do something like this with XMacros so the mapping gets taken care of at compile time. Might be able to come up with a solution using this: internals.rust-lang.org/t/x-macro-... - Kind of a pain to set up, though!
It's not ideal, but I'm not too concerned. In my benchmarks versus the switch style, it's about half as fast to process a command. Startup time is of course greatly increased, but since the system allows for new commands to be later added during runtime, program startup doesn't need to happen often.
I can't speak for every situation, but my Discord bots aren't super performance-critical, so I find the maintainability and expressive freedom offered by this solution to be a much bigger win.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I like your approach! It's sad however that it requires a map :(
In fact it does not. You can use it even in C with structures like:
gist.github.com/wefhy/4fa3039bac8a...
And additionally you can automatically generate help message from this.
But I also love Rust for things like this ;)
In C/C++ you could do something like this with XMacros so the mapping gets taken care of at compile time. Might be able to come up with a solution using this: internals.rust-lang.org/t/x-macro-... - Kind of a pain to set up, though!
It's not ideal, but I'm not too concerned. In my benchmarks versus the switch style, it's about half as fast to process a command. Startup time is of course greatly increased, but since the system allows for new commands to be later added during runtime, program startup doesn't need to happen often.
I can't speak for every situation, but my Discord bots aren't super performance-critical, so I find the maintainability and expressive freedom offered by this solution to be a much bigger win.