Skip to content

Commit

Permalink
Merge pull request rustformers#429 from chris-ha458/map_or
Browse files Browse the repository at this point in the history
few unwrap removes
  • Loading branch information
philpax authored Sep 18, 2023
2 parents 05d5d85 + c5a8880 commit c6630d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
3 changes: 1 addition & 2 deletions binaries/llm-cli/src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ fn session_ends_with_newline(session: &llm::InferenceSession) -> bool {
session
.decoded_tokens()
.last()
.map(|t| *t == b'\n')
.unwrap_or(true)
.map_or(true, |t| *t == b'\n')
}

fn readline_loop(mut body: impl FnMut(String) -> eyre::Result<()>) -> eyre::Result<()> {
Expand Down
4 changes: 1 addition & 3 deletions binaries/llm-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ fn info(args: &cli_args::Info) -> eyre::Result<()> {
}

fn utf8_or_array(token: &[u8]) -> String {
std::str::from_utf8(token)
.map(|s| s.to_owned())
.unwrap_or(format!("{:?}", token))
std::str::from_utf8(token).map_or(format!("{:?}", token), |s| s.to_owned())
}

Ok(())
Expand Down
20 changes: 9 additions & 11 deletions crates/llm-base/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,17 @@ fn collect_related_paths(
p.file_name()
.and_then(|p| p.to_str())
.zip(main_filename)
.map(|(part_filename, main_filename)| {
match part_filename.strip_prefix(main_filename) {
Some(suffix) => {
suffix.is_empty()
|| (suffix
.strip_prefix('.')
.map(|s| s.parse::<usize>().is_ok())
.unwrap_or(false))
}
None => false,
.map_or(false, |(part_filename, main_filename)| match part_filename
.strip_prefix(main_filename)
{
Some(suffix) => {
suffix.is_empty()
|| (suffix
.strip_prefix('.')
.map_or(false, |s| s.parse::<usize>().is_ok()))
}
None => false,
})
.unwrap_or(false)
})
.collect();
paths.sort();
Expand Down

0 comments on commit c6630d4

Please sign in to comment.