From 56a07c5c4b3004ce478b0d93f2cbe57ffb5c2c49 Mon Sep 17 00:00:00 2001 From: blacktoast Date: Wed, 13 Oct 2021 08:11:10 +0000 Subject: [PATCH] =?UTF-8?q?=EC=97=90=EB=9F=AC=20=ED=91=B8=EB=8A=94?= =?UTF-8?q?=EC=A4=91..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/error_handling/errors1.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index 9c24d85d..2fb17664 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -6,14 +6,15 @@ // this function to have. // Execute `rustlings hint errors1` for hints! -// I AM NOT DONE -pub fn generate_nametag_text(name: String) -> Option { +pub fn generate_nametag_text(name: String) -> Result { if name.len() > 0 { - Some(format!("Hi! My name is {}", name)) + Ok(format!("Hi! My name is {}", name)) } else { // Empty names aren't allowed. - None + Err("`name` was empty; it must be nonempty.".into()) + + } } @@ -28,12 +29,13 @@ mod tests { fn generates_nametag_text_for_a_nonempty_name() { assert_eq!( generate_nametag_text("Beyoncé".into()), - Some("Hi! My name is Beyoncé".into()) + Ok("Hi! My name is Beyoncé".into()) ); } #[test] fn explains_why_generating_nametag_text_fails() { + println!("{:?}",generate_nametag_text("".into())); assert_eq!( generate_nametag_text("".into()), Err("`name` was empty; it must be nonempty.".into())