Finally figured out ?

This commit is contained in:
Justin Kelz 2022-04-01 21:47:06 -07:00
parent 754a006da8
commit c393f0e6e5

View File

@ -16,16 +16,20 @@
// There are at least two ways to implement this that are both correct-- but // There are at least two ways to implement this that are both correct-- but
// one is a lot shorter! Execute `rustlings hint errors2` for hints to both ways. // one is a lot shorter! Execute `rustlings hint errors2` for hints to both ways.
// I AM NOT DONE
use std::num::ParseIntError; use std::num::ParseIntError;
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> { pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
let processing_fee = 1; let processing_fee = 1;
let cost_per_item = 5; let cost_per_item = 5;
let qty = item_quantity.parse::<i32>(); let qty = item_quantity.parse::<i32>()/*?*/;
// The slick answer is just skipping
Ok(qty * cost_per_item + processing_fee) // the match statement and putting a ? where I left it in the comments.
// It does the same thing as the match statement below.
match qty {
Ok(qty) => Ok(qty * cost_per_item + processing_fee),
Err(ParseIntError) => Err(ParseIntError),
}
} }
#[cfg(test)] #[cfg(test)]