fn main() {

// get result when you sure there's no error
    let r = squared_reciprocal(2).unwrap();
    println!("{}", r);

    // unwrap with default value in case of error
    let r = squared_reciprocal(0).unwrap_or(0.0);
    println!("{}", r);

    let r = squared_reciprocal(0).unwrap_or_else(|_| 0.0);
    println!("{}", r);
}

fn squared_reciprocal(n: i32) -> Result<f64, &'static str> {
    // propagating error with `?`
    let rec = reciprocal(n)?;
    Ok(rec * rec)
}

fn reciprocal(n: i32) -> Result<f64, &'static str> {
    match n {
        0 => Err("Can't divide to 0"),
        _ => Ok(1.0 / n as f64),
    }
}