From 3bd4661bf494a18133f0c8c85db82975075e5e1b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 23 Dec 2020 23:22:41 +0100 Subject: Cleanup: Replace nested matches with method chaining Signed-off-by: Matthias Beyer --- src/util.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/util.rs b/src/util.rs index 4724091..1ce5943 100644 --- a/src/util.rs +++ b/src/util.rs @@ -2,14 +2,11 @@ use crate::resp_types::{RespLoginInfo, RespMinimalAuthorInfo}; pub fn abbreviate_link(href: &str) -> &str { // Attempt to find the hostname from the URL - match href.find("://") { - Some(idx1) => match href[(idx1 + 3)..].find('/') { - Some(idx2) => Some(&href[(idx1 + 3)..(idx1 + 3 + idx2)]), - None => None, - }, - None => None, - } - .unwrap_or(href) + href.find("://") + .and_then(|idx1| { + href[(idx1 + 3)..].find('/').map(|idx2| &href[(idx1 + 3)..(idx1 + 3 + idx2)]) + }) + .unwrap_or(href) } pub fn author_is_me( -- cgit v1.2.3