using match to capture the error

This commit is contained in:
Hariettemaina 2023-05-22 17:03:05 +03:00
parent d748cd156f
commit 938bf326df

View File

@ -17,16 +17,20 @@
// one is a lot shorter!
// Execute `rustlings hint errors2` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
use std::num::ParseIntError;
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
let processing_fee = 1;
let cost_per_item = 5;
let qty = item_quantity.parse::<i32>();
Ok(qty * cost_per_item + processing_fee)
match item_quantity.parse::<i32>(){
Ok(qty) => Ok(qty * cost_per_item + processing_fee),
Err(err)=> Err(err),
}
}
#[cfg(test)]