diff --git a/bipc/src/lib.rs b/bipc/src/lib.rs index 031b367..d483ca7 100644 --- a/bipc/src/lib.rs +++ b/bipc/src/lib.rs @@ -7,11 +7,10 @@ pub type Result = std::result::Result; #[derive(Debug)] pub enum Error { ReadError, - BadPath, - BadOutPath, BadFile, BadRead(String), BadWrite(std::io::Error), + BadPath(std::io::Error), BpError(bp::Error), ParseError(bip::ParseError), } @@ -20,11 +19,10 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::ReadError => write!(f, "errors found"), - Self::BadPath => write!(f, "bad file path"), - Self::BadOutPath => write!(f, "bad output file path"), Self::BadFile => write!(f, "invalid text"), Self::BadRead(e) => write!(f, "{e}"), Self::BadWrite(e) => write!(f, "{e}"), + Self::BadPath(e) => write!(f, "{e}"), Self::BpError(e) => write!(f, "{e}"), Self::ParseError(e) => write!(f, "{e}"), } @@ -58,16 +56,10 @@ fn read_bip(buf: R) -> Result> { } pub fn run(path: &str, outfile: &str) -> Result<()> { - let f = match std::fs::File::open(path) { - Ok(f) => f, - Err(_) => return Err(Error::BadPath), - }; + let f = std::fs::File::open(path).map_err(Error::BadPath)?; let node_tree = read_bip(BufReader::new(f))?; - let mut out = match std::fs::File::create(outfile) { - Ok(f) => f, - Err(_) => return Err(Error::BadOutPath), - }; + let mut out = std::fs::File::create(outfile).map_err(Error::BadPath)?; bp::Writer::new() .parse_tree(&node_tree)