Hi Colin,
here are some minor cleanup patches for a bit more idomatic Rust.
Best,
Matthias
Matthias Beyer (4):
Cleanup: Return value from server awaiting
Cleanup: Replace nested matches with method chaining
Cleanup: Use method chaining instead of wrapping in Ok()
Cleanup: Replace match with method chaining
src/main.rs | 4 +---
src/routes/mod.rs | 23 ++++++++++-------------
src/util.rs | 13 +++++--------
3 files changed, 16 insertions(+), 24 deletions(-)
--
2.29.2
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
---
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(
--
2.29.2