Skip to content

Commit

Permalink
fix: retain unsafe property of Mmap::map in separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
nc7s committed Nov 16, 2023
1 parent 601db39 commit 559dfcb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ impl Source {
}
}

pub(crate) fn make_mmap(path: &PathBuf) -> Result<Mmap> {
Ok(unsafe { Mmap::map(&File::open(path)?)? })
// TODO: memmap2 docs state that users should implement proper
// procedures to avoid problems the `unsafe` keyword indicate.
// This would be in a later PR.
pub(crate) unsafe fn make_mmap(path: &PathBuf) -> Result<Mmap> {
Ok(Mmap::map(&File::open(path)?)?)
}

pub(crate) fn make_mmap_stdin() -> Result<Mmap> {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() -> Result<()> {
for source in sources.iter() {
let maybe_mmap = match source {
Source::File(path) => if path.exists() {
make_mmap(&path)
unsafe { make_mmap(&path) }
} else {
Err(Error::InvalidPath(path.clone()))
},
Expand Down

0 comments on commit 559dfcb

Please sign in to comment.