WPM bersih0
WPM0
Ketepatan100%
Lupa Lenyap0s
Waktu—
Aksara mata rantai0
koreksi0
Ralat0
Kemajuan Internet0%
Nama Caps Lock On

Panduan petunjuk kode baca code code code code lema

Bahasa Pemrograman Bahasa
Rust
Kesulitan Liar
♪ Hard ♪

Parse a number and propagate a readable error.

fn parse_count(input: &str) -> Result<u32, String> {
    input
        .trim()
        .parse::<u32>()
        .map_err(|error| format!("invalid count: {error}"))
}

fn main() -> Result<(), String> {
    let count = parse_count("42")?;
    println!("{count}");
    Ok(())
}