Skip to content

Commit

Permalink
Use unwrap_or when creating relative path in loader (#2400)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Sep 30, 2024
1 parent 66ccef7 commit 5089bf7
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ impl Loader {
path: &Path,
) -> RunResult<(&'src Path, &'src str)> {
let src = fs::read_to_string(path).map_err(|io_error| Error::Load {
path: path.to_owned(),
path: path.into(),
io_error,
})?;

let relative = if let Ok(path) = path.strip_prefix(root.parent().unwrap()) {
path
} else {
path
};
let relative = path.strip_prefix(root.parent().unwrap()).unwrap_or(path);

Ok((self.paths.alloc(relative.into()), self.srcs.alloc(src)))
}
Expand Down

0 comments on commit 5089bf7

Please sign in to comment.