diff options
author | Teddy Wing | 2021-04-11 20:15:25 +0200 |
---|---|---|
committer | Teddy Wing | 2021-04-11 20:15:25 +0200 |
commit | 23de87271c42b94ee5b273fb358ee362facdcaec (patch) | |
tree | 4afc8da0fc33dfac3d5559880d8a609b75a344c1 /src | |
parent | 01c82770392b23176b4693d4456109f41a50fe45 (diff) | |
download | formurapid-23de87271c42b94ee5b273fb358ee362facdcaec.tar.bz2 |
generate_fill_helpers(): Replace `unwrap`s with `anyhow::Result`s
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs index e064bfc..2487d78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,7 +72,7 @@ fn main() { toml_path, ids_path, &mut form, - ); + ).unwrap(); } else { print_usage(&opts); @@ -84,7 +84,7 @@ fn generate_fill_helpers<P: AsRef<Path>>( data_path: P, output_path: P, form: &mut Form, -) { +) -> anyhow::Result<()> { let mut data = TextForm::default(); for i in 0..form.len() { @@ -92,21 +92,21 @@ fn generate_fill_helpers<P: AsRef<Path>>( match field_type { FieldType::Text => { - form.set_text(i, format!("{}", i)).unwrap(); + form.set_text(i, format!("{}", i))?; - data.fields.push(FieldBuilder::default() - .id(i) - .value(Some("")) - .build() - .unwrap() + data.fields.push( + FieldBuilder::default() + .id(i) + .value(Some("")) + .build()? ); }, FieldType::CheckBox => { - data.fields.push(FieldBuilder::default() - .id(i) - .state(Some(false)) - .build() - .unwrap() + data.fields.push( + FieldBuilder::default() + .id(i) + .state(Some(false)) + .build()? ); }, _ => (), @@ -116,11 +116,12 @@ fn generate_fill_helpers<P: AsRef<Path>>( let mut toml_file = OpenOptions::new() .create_new(true) .write(true) - .open(data_path) - .unwrap(); - toml_file.write_all(&toml::to_vec(&data).unwrap()).unwrap(); + .open(data_path)?; + toml_file.write_all(&toml::to_vec(&data)?)?; - form.save(output_path).unwrap(); + form.save(output_path)?; + + Ok(()) } fn fill<P: AsRef<Path>>( |