use std::str::FromStr;

fn main() {
    let a = i32::from_str("-123");
    let b = i32::from_str("ABC");
    println!("{:?}, {:?}", a.err(), b.err());

    let a = i32::from_str("-123");
    if a.is_ok() {
        println!("成功: {}", a.unwrap());
    } else {
        println!("失敗: {:?}", a.err());
    }

    let a = i32::from_str("ABC").unwrap_or(-1);
    println!("{a}");
    let a = i32::from_str("ABC").unwrap_or_default();
    println!("{a}");
    let a = i32::from_str("ABC").unwrap_or_else(|_| -2);
    println!("{a}");

    let a = i32::from_str("-123")
        .inspect(|x| println!("加工前: {}", x))
        .map(|x| x + 1)
        .unwrap();
    println!("加工後: {a}");
}