Skip to content

Commit e8fb404

Browse files
committed
Replace manual expressions with map_or[_else]()
This fixes the only occurrence of `clippy::option_if_let_else` and the only occurrence of `clippy::map_unwrap_or`
1 parent 055b2b1 commit e8fb404

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

src/blogs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ fn load_recursive(base: &Path, current: &Path, blogs: &mut Vec<Blog>) -> eyre::R
140140
if file_name == MANIFEST_FILE {
141141
let prefix = parent
142142
.strip_prefix(base)
143-
.map(|p| p.to_path_buf())
144-
.unwrap_or_else(|_| PathBuf::new());
143+
.map_or_else(|_| PathBuf::new(), Path::to_path_buf);
145144
blogs.push(Blog::load(prefix, parent)?);
146145
}
147146
}

src/posts.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,21 @@ impl Post {
114114
}
115115

116116
// If they supplied team, it should look like `team-text <team-url>`
117-
let (team, team_url) = match team_string {
118-
Some(s) => {
119-
lazy_static::lazy_static! {
120-
static ref R: Regex = Regex::new(r"(?P<name>[^<]*) <(?P<url>[^>]+)>").unwrap();
121-
}
122-
let Some(captures) = R.captures(&s) else {
123-
panic!(
124-
"team from path `{}` should have format `$name <$url>`",
125-
path.display()
126-
)
127-
};
128-
(
129-
Some(captures["name"].to_string()),
130-
Some(captures["url"].to_string()),
131-
)
117+
let (team, team_url) = team_string.map_or((None, None), |s| {
118+
lazy_static::lazy_static! {
119+
static ref R: Regex = Regex::new(r"(?P<name>[^<]*) <(?P<url>[^>]+)>").unwrap();
132120
}
133-
134-
None => (None, None),
135-
};
121+
let Some(captures) = R.captures(&s) else {
122+
panic!(
123+
"team from path `{}` should have format `$name <$url>`",
124+
path.display()
125+
)
126+
};
127+
(
128+
Some(captures["name"].to_string()),
129+
Some(captures["url"].to_string()),
130+
)
131+
});
136132

137133
Ok(Self {
138134
filename,

0 commit comments

Comments
 (0)