Rust Beginner: flatten nested matches This is how I implemented the guessing game - chapter 2 of the Rust book: https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html
use std::io;
use std::io::Error;
use std::cmp::Ordering;
use std::num::ParseIntError;

use rand::Rng;


enum MyReadLineError {
    FailReadLine(Error)
}

#[derive(Debug)]
enum MyReadU32Line {
    FailReadLine(Error),
    FailParse(ParseIntError)
}


fn my_read_line() -&gt; Result&lt;String, MyReadLineError&gt; {
    let mut input = String::new();
    let result = io::stdin().read_line(&amp;mut input);
    match result {
        Ok(_) =&gt; Ok(input),
        Err(error ) =&gt; Err(MyReadLineError::FailReadLine(error)),
    }
}

fn my_read_u32_line() -&gt; Result&lt;u32, MyReadU32Line&gt; {
    match my_read_line() {
        Result::Ok(line) =&gt;
            match line.trim().parse::&lt;u32&gt;() {
                Ok(value) =&gt; Ok(value),
                Err(error) =&gt; Err(MyReadU32Line::FailParse(error)),
            }

        Result::Err(MyReadLineError::FailReadLine(error)) =&gt; Err(MyReadU32Line::FailReadLine(error)),
    }
}

fn main() {
    println!(&quot;Guess the number!&quot;);

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

    loop {
        println!(&quot;Please input your guess.&quot;);
        let guess = my_read_u32_line();
        match guess {
            Ok (value) =&gt; match value.cmp(&amp;secret_number) {
                Ordering::Less =&gt; println!(&quot;Too small!&quot;),
                Ordering::Greater =&gt; println!(&quot;Too big!&quot;),
                Ordering::Equal =&gt; {
                    println!(&quot;You win!&quot;);
                    break;
                },
            }
            Err (_) =&gt; println!(&quot;Sorry I couldn't read a u32 from your input! Please try again.&quot;),
        }
    }
}

This works as expected but I would like to flatten the matches so that doesn't look at verbose, is that possible. Also is there any other way to make that code look better, more readable?
Welcome to Rust!
Code Formatting
There are some inconsistencies in your formatting — I have run
cargo fmt to get rid of them.
Naming
There's no need to prefix everything with My or my_ — in
Rust, your names won't as easily clash with existing names as might be
the case in certain other languages.
Error handling
For applications, I suggest using the anyhow crate to manage
errors — it reduces much of the boilerplate.  Just add
anyhow = &quot;1.0&quot;

to the [dependencies] section of your Cargo.toml.
Helper functions
The my_read_line function can be simplified with the ? operator:
use anyhow::Result;

fn read_line() -&gt; Result&lt;String&gt; {
    let mut input = String::new();
    io::stdin().read_line(&amp;mut input)?;
    Ok(input)
}

my_read_u32_line can be similarly simplified:
fn read_u32() -&gt; Result&lt;u32&gt; {
    Ok(read_line()?.trim().parse()?)
}

Magic numbers
We can define constants for the range of the number:
const MIN: u32 = 1;
const MAX: u32 = 100;

// later
let secret_number = rand::thread_rng().gen_range(MIN, MAX + 1);

Organization
I might reorganize the main function to reduce indentation:
loop {
    println!(&quot;Please input your guess.&quot;);

    let guess = match read_u32() {
        Ok(guess) =&gt; guess,
        Err(_) =&gt; {
            println!(
                &quot;Sorry I couldn't read a u32 from your input! \
                Please try again.&quot;
            );
            continue;
        }
    };

    match guess.cmp(&amp;secret_number) {
        Ordering::Less =&gt; println!(&quot;Too small!&quot;),
        Ordering::Greater =&gt; println!(&quot;Too big!&quot;),
        Ordering::Equal =&gt; {
            println!(&quot;You win!&quot;);
            break;
        }
    };
}

Final result
use anyhow::Result;
use rand::Rng;
use std::cmp::Ordering;
use std::io;

const MIN: u32 = 1;
const MAX: u32 = 100;

fn read_line() -&gt; Result&lt;String&gt; {
    let mut input = String::new();
    io::stdin().read_line(&amp;mut input)?;
    Ok(input)
}

fn read_u32() -&gt; Result&lt;u32&gt; {
    Ok(read_line()?.trim().parse()?)
}

fn main() {
    println!(&quot;Guess the number!&quot;);

    let secret_number = rand::thread_rng().gen_range(MIN, MAX + 1);

    loop {
        println!(&quot;Please input your guess.&quot;);

        let guess = match read_u32() {
            Ok(guess) =&gt; guess,
            Err(_) =&gt; {
                println!(
                    &quot;Sorry I couldn't read a u32 from your input! \
                    Please try again.&quot;
                );
                continue;
            }
        };

        match guess.cmp(&amp;secret_number) {
            Ordering::Less =&gt; println!(&quot;Too small!&quot;),
            Ordering::Greater =&gt; println!(&quot;Too big!&quot;),
            Ordering::Equal =&gt; {
                println!(&quot;You win!&quot;);
                break;
            }
        };
    }
}