Avatar ·

How to convert a String to an integer (int) in Rust?

Hello everyone! I just started learning Rust, coming from Python, and I encountered a problem converting a string to a number. In Python I'm used to writing `int("123")` and getting the number 123. But in Rust it turned out to be more complicated. I have a variable: ```rust let input = String::from("42"); let number: i32 = input; // Error! ``` The compiler gives an error: `expected i32, found String`. I understand that Rust is a strictly typed language, and you can't just assign a string to a number. I tried using `as` for type casting: ```rust let number: i32 = input as i32; // Also an error ``` But that doesn't work either. I've read that in Rust you need to use the `parse()` method, but I don't understand how to apply it correctly. What to do if the string might be invalid (e.g., "abc")? How to handle