Control Flow - Rust

pub fn download(path: &str)
-> Result<Success, Fail> {
    // ..
}

pub enum Success {
    Downloaded,
    Cached,
}

pub enum Fail {
    UnknownHost(io::Error),
    ConnectionLost(io::Error),
    OutOfDiskSpace {
        path: PathBuf,
        error: io::Error,
    },
}

Usage

#![deny(unused_must_use)]
fn main() {
// Use `download()`
let result = download("/tmp/a_file.txt");
match result {
    Ok(Success::Downloaded) => {}
    Ok(Success::Cached) => {}
    Err(Fail::UnknownHost(_)) => {}
    Err(Fail::ConnectionLost(_)) => {}
    Err(Fail::OutOfDiskSpace { .. }) => {}
}

match download("/tmp/b_file.txt") {
    Ok(_) => {}
    Err(Fail::UnknownHost(_)) => {}
    Err(Fail::ConnectionLost(_)) => {}
    Err(Fail::OutOfDiskSpace { .. }) => {}
}

upload("/tmp/a_file.txt");
// match upload_outcome {
//     Ok(_) => {}
//     Err(FailUpload::UnknownHost(_)) => {}
//     Err(FailUpload::ConnectionLost(_)) => {}
// }
}

pub fn download(_s: &str) -> Result<Success, Fail> {
    Ok(Success::Downloaded)
}
pub fn upload(_s: &str) -> Result<Success, FailUpload> {
    Ok(Success::Downloaded)
}

pub enum Success {
    Downloaded,
    Cached,
}

pub enum Fail {
    UnknownHost(std::io::Error),
    ConnectionLost(std::io::Error),
    OutOfDiskSpace {
        path: std::path::PathBuf,
        error: std::io::Error,
    },
}

pub enum FailUpload {
    UnknownHost(std::io::Error),
    ConnectionLost(std::io::Error),
}