From 459010939d0ed35674707060ce6ebae89ea07fab Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 12 Feb 2022 18:48:48 +0100 Subject: [PATCH] joke_bot: Replace match with only one non-empty branch with if let --- examples/joke_bot/src/main.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/joke_bot/src/main.rs b/examples/joke_bot/src/main.rs index 9badae8d..3996504e 100644 --- a/examples/joke_bot/src/main.rs +++ b/examples/joke_bot/src/main.rs @@ -95,19 +95,17 @@ async fn run() -> Result<(), Box> { let message_futures = response.rooms.join.iter().map(|(room_id, room_info)| async move { // Use a regular for loop for the messages within one room to handle them sequentially for e in &room_info.timeline.events { - match handle_messages(http_client, matrix_client, e, room_id, user_id).await { - Ok(_) => {} - Err(err) => { - eprintln!("failed to respond to message: {}", err) - } + if let Err(err) = + handle_messages(http_client, matrix_client, e, room_id, user_id).await + { + eprintln!("failed to respond to message: {}", err) } } }); let invite_futures = response.rooms.invite.iter().map(|(room_id, _)| async move { - match handle_invitations(http_client, matrix_client, room_id).await { - Ok(_) => {} - Err(err) => eprintln!("failed to accept invitation for room {}: {}", &room_id, err), + if let Err(err) = handle_invitations(http_client, matrix_client, room_id).await { + eprintln!("failed to accept invitation for room {}: {}", &room_id, err) } });