From ca1b3e0d3215d4e4c0c60c5ff6bf5c99597cae7e Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 8 Jun 2022 17:39:30 -0400 Subject: Based on readability feedback, this is clearer. --- src/view.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/view.rs') diff --git a/src/view.rs b/src/view.rs index ba15915..2062522 100644 --- a/src/view.rs +++ b/src/view.rs @@ -140,8 +140,10 @@ async fn index( None => data.0.choose(&mut thread_rng()), }; - let thing = thing.ok_or_else(|| error::ErrorNotFound("Not found"))?; - let (index, thing) = thing.to_owned(); + let (index, thing) = match thing { + Some(thing) => thing.to_owned(), + None => return Err(error::ErrorNotFound("Not found")), + }; let response = Suggestion { thing, req, index }; let response = response @@ -161,7 +163,10 @@ struct SlackMessage<'a> { async fn slack_troubleshoot(data: web::Data) -> error::Result { let thing = data.0.choose(&mut thread_rng()); - let (_, thing) = thing.ok_or_else(|| error::ErrorNotFound("Not found"))?; + let (_, thing) = match thing { + Some(thing) => thing.to_owned(), + None => return Err(error::ErrorNotFound("Not found")), + }; let response = SlackMessage { response_type: "in_channel", -- cgit v1.2.3