diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-23 23:22:41 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-01-08 20:07:26 +0100 |
commit | 3bd4661bf494a18133f0c8c85db82975075e5e1b (patch) | |
tree | 56f2717debd840ae448a463176cdc1ff8c803308 | |
parent | 4a9db64bcf1f00c3cd0650a7b9d7dd94972625e8 (diff) |
Cleanup: Replace nested matches with method chaining
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/util.rs | 13 |
1 files 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( |