concept upstream error in category rust

appears as: upstream errors, upstream errors, upstream error
Rust in Action

This is an excerpt from Manning's book Rust in Action.

It is possible to retain the upstream errors, but requires some more work on our behalf. We need to bundle upstream errors in our own type. When the upstream errors are needed later, say for reporting errors to the user, it’s possible to extract them with pattern matching.

Listing 8. 18. Wrapping upstream errors in our own type to retain type safety (ch8/misc/wraperror.rs)
use std::io;
use std::fmt;
use std::net;
use std::fs::File;
use std::net::Ipv6Addr;

#[derive(Debug)]
enum UpstreamError{
  IO(io::Error),
  Parsing(net::AddrParseError),
}

impl fmt::Display for UpstreamError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}

impl error::Error for UpstreamError { }

fn main() -> Result<(), UpstreamError> {
    let _f = File::open("invisible.txt").map_err(UpstreamError::IO)?;
    let _localhost = "::1".parse::<Ipv6Addr>().map_err(UpstreamError::Parsing)?;

    Ok(())
}