thomas-shirley.com

.Parse()

Parse is a very cool function. But it can handle the juggling between so many different datatyptes, it's important to confirm which datatype you really want to convert to.

This can be achieved by setting the data type on the variable assignment, e.g:

    let my_variable: i32 = input.trim().parse().unwrap();

The trim is necessary, as whenever information is read from stdin, it contains a /n character, denoting a new line.

or, using something called turbo fish:

    let my_variable = input.parse::<i32>();

Note with the second option, you don't need to call the unwrap functions. This has something to do with enums, which apparently I'll learn about soon.

30-08-2021