Is it possible to change which variable is used based on user input?

🙋 seeking help & advice

In my project, I have multiple named vectors, and would like to iterate over one of them based on which name the user types.
I'm aware "match" can/should be used here, but the code that needs to be executed for each vector is identical aside from the vectors' names, making a match expression seem unnessecarily verbose.

Here is an example of what I'm trying to do

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=eb0254d91946f269b061028cef31a3c5

I'd taken a look around the internet, but can't seem to find anything quite relating to my problem, which makes me slightly worried I'm looking at his from the wrong perspective.
I'm quite new to Rust, so if my approach/question doesn't make any sense, please do let me know. I would greatly appreciate any help.

Posted Jan 27, 2026, 11:37 AM UTC

016
Loading comments…