diff options
author | Teddy Wing | 2021-04-11 20:10:39 +0200 |
---|---|---|
committer | Teddy Wing | 2021-04-11 20:10:39 +0200 |
commit | 01c82770392b23176b4693d4456109f41a50fe45 (patch) | |
tree | b43b4e6513855d5dcc47d09782fe422f2eaeb655 /src | |
parent | 0acbf02b7e380ac352f3e090023d9f9b28fbdb30 (diff) | |
download | formurapid-01c82770392b23176b4693d4456109f41a50fe45.tar.bz2 |
fill(): Remove `unwrap`s
Replace these with 'anyhow' `Result`s.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 8961809..e064bfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use anyhow; use derive_builder::Builder; use getopts::Options; use pdf_forms::{Form, FieldType}; @@ -61,7 +62,7 @@ fn main() { toml_path, form_path.with_file_name(output_file_name), &mut form, - ); + ).unwrap(); } else if opt_matches.opt_present("generate") { let ids_path = form_path.with_file_name( format!("{}-ids.pdf", form_file_prefix) @@ -126,20 +127,22 @@ fn fill<P: AsRef<Path>>( data_path: P, output_path: P, form: &mut Form, -) { +) -> anyhow::Result<()> { let mut buf = Vec::new(); - let mut file = File::open(data_path).unwrap(); - file.read_to_end(&mut buf).unwrap(); + let mut file = File::open(data_path)?; + file.read_to_end(&mut buf)?; - let data: TextForm = toml::from_slice(&buf).unwrap(); + let data: TextForm = toml::from_slice(&buf)?; for field in data.fields { if let Some(value) = field.value { - form.set_text(field.id, value.to_owned()).unwrap(); + form.set_text(field.id, value.to_owned())?; } else if let Some(state) = field.state { - form.set_check_box(field.id, state).unwrap(); + form.set_check_box(field.id, state)?; } } - form.save(output_path).unwrap(); + form.save(output_path)?; + + Ok(()) } |