Guessing_Game Compile Issue

let guess: u32 = guess.trim().parse() {

        Ok(num) => num,

        Err(_) => continue,


The opening curly-bracket is throwing an error:

^ expected one of ., ;, ?, or an operator

rustc 1.44.1 (c7087fe00 2020-06-17)
cargo 1.44.1 (88ba85757 2020-06-11)
cargo.toml -
name = "guessing_game"
version = "0.1.0"
authors = ["microsoft"]
edition = "2018"

See more keys and their definitions at

rand = "0.5.5"

src/ -
use std::io;

use std::cmp::Ordering;

use rand::Rng;

fn main() {

println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1, 101);

println!("The secret number is: {}", secret_number);

loop {

    println!("Please input your guess.");

    let mut guess = String::new();


        .read_line(&mut guess)

        .expect("Failed to read line");

    let guess: u32 = guess.trim().parse() {   

        Ok(num) => num,

        Err(_) => continue,


    println!("You guessed: {}", guess);

    match guess.cmp(&secret_number) {

        Ordering::Less => println!("Too small!"),

        Ordering::Greater => println!("Too big!"),

        Ordering::Equal => { 

            println!("You win!");






You're missing a match:

        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
1 Like

That worked. I don't know how I didn't put that in place. I appreciate your help. Thanks.

Can I close this issue out?

You can select @mitnk's post as the Solution to mark the thread solved. There's a tick button for that.

1 Like

When you post code, please follow the instructions for new posters that are pinned to the top of the forum. It is unnecessarily difficult for other forum readers to read your code when you do not follow those instructions. Therefore many readers will simply ignore your posts.

You can use the edit button under any of your existing posts to add the two lines (of ```, three backticks), one before and one after your code, that will cause those posts to format as Rust code.

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.