Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unwrap_or when creating relative path in loader #2400

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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