jeudi 24 janvier 2019

How can I propagate the errors in Rust?

Is there a nice way to propagate errors in Rust? E.g, I'd like to refactor the following code to avoid nested errors:

match f1() {
    Ok(a1) => match f2() {
        Ok(a2) => {
            match f3() {
                Ok(_) => {

                }
                Err(e) => {
                    eprintln!("Error: {}", e);
                }
            }
        }
        Err(e) => {
            eprintln!("Error: {}", e);
        }
    },
    Err(e) => {
        eprintln!("Error: {}", e);
    }
};

Aucun commentaire:

Enregistrer un commentaire