Reading integer type input from user


Hi! I am new to this programming language.
I want to know how can I read input from the user(integer) without using parse or unwrap?
Also, what will be the most efficient manner to read several variables in a program from the user?
Thanks in advance!



You need to parse the input, as the input is always a string. Also you need to unwrap the parsed result either using unwrap, except or pattern matching, to deal with invalid inputs.

Of course you can implement parse yourself, but that’s error prone.

The most efficient way to read many integers from the input is probably to iterate over the input and apply parse to each of the items and finally collect into a Vec.

1 Like