A variable can be created by let binding, e.g.,
let a = 0;
The above variable has name "a", can we accept the name from user input?
A variable can be created by let binding, e.g.,
let a = 0;
The above variable has name "a", can we accept the name from user input?
No, this doesn't work. This also sounds like an XY problem, what are you trying to achieve?
If you want to create a mapping from strings (from user input) to values, you should take a look at hashmaps. A HashMap<String, i32>
can store strings as keys and integers as their corresponding values.
In Rust you won't be able to dynamically refer to anything in the source code. It's a compiled language, and all knowledge of all variables is completely removed during compilation. They don't exist in the running program any more.
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.