diff --git a/build.rs b/build.rs index 810eeb9..fce1c5b 100644 --- a/build.rs +++ b/build.rs @@ -29,7 +29,7 @@ use std::{ io::{ Error, Write }, - process::{ Command, exit, Stdio }, + process::{ Command, Stdio }, path::PathBuf, }; @@ -51,11 +51,9 @@ fn main() -> Result<(), Error> { let output = process.wait_with_output()?.stdout; - let headers = String::from_utf8(output).unwrap_or_else( |e| { - Error::other(e.to_string()); - /* Exit with status 1 because we’re bootstrapping sysexits.h, silly! */ - exit(1); - }); + let headers = String::from_utf8(output).map_err(|e| { + Error::other(e.to_string()) + })?; /* Split headers by spaces because cpp(1) returns more than one */ for h in headers.split(' ') { @@ -73,11 +71,9 @@ fn main() -> Result<(), Error> { .header(header) .parse_callbacks(Box::new(CargoCallbacks::new())) .generate() - .expect("Unable to generate bindings."); + .map_err(|e| Error::other(e.to_string()))?; - bindings - .write_to_file(PathBuf::from("src/").join("lib.rs")) - .expect("Couldn't write bindings!"); + bindings.write_to_file(PathBuf::from("src/").join("lib.rs"))?; Ok(()) }