Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there any way to get a function pointer from a &str type in rust which is provided by the use

Is there any way to get a function pointer from a &str type in rust which is provided by the use.
Example: use provides a name of a function provided by the user i need some way to call the function preferably a closure or a function pointer

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Rust is a static, compiled language. There is no access to functions by name at runtime. The functions may not even exist (they may be inlined, for example, or optimized away). Instead, what you need to do is create a HashMap of Strings to functions you would like to call at runtime, or use a match to dispatch by string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading