From d279e7e1914348bf266afc38d9275ed5976c614a Mon Sep 17 00:00:00 2001 From: Justin Kelz Date: Sun, 3 Apr 2022 17:58:38 -0700 Subject: [PATCH] It's OK to return Result<(),E> in main --- exercises/error_handling/errors3.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/error_handling/errors3.rs b/exercises/error_handling/errors3.rs index 460ac5c4..a4fa8741 100644 --- a/exercises/error_handling/errors3.rs +++ b/exercises/error_handling/errors3.rs @@ -8,11 +8,11 @@ use std::num::ParseIntError; -fn main() { +fn main() -> Result<(),ParseIntError> { // This isn't too bad, main should return (), so we just float the result structure up to main. let mut tokens = 100; let pretend_user_input = "8"; - let cost = total_cost(pretend_user_input)?; + let cost = total_cost(pretend_user_input)?; // Here we're making cost a result if cost > tokens { println!("You can't afford that many!"); @@ -20,6 +20,8 @@ fn main() { tokens -= cost; println!("You now have {} tokens.", tokens); } + Ok(()) // :facepalm: So, I was on https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html at the final example. + // Wish I had read further } pub fn total_cost(item_quantity: &str) -> Result {