From 559dfcb949961d43a6deff7ef262016eb0f3c810 Mon Sep 17 00:00:00 2001 From: Blair Noctis Date: Thu, 16 Nov 2023 19:56:40 +0800 Subject: [PATCH] fix: retain unsafe property of Mmap::map in separate function --- src/input.rs | 7 +++++-- src/main.rs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/input.rs b/src/input.rs index 4cb9e62..b078686 100644 --- a/src/input.rs +++ b/src/input.rs @@ -26,8 +26,11 @@ impl Source { } } -pub(crate) fn make_mmap(path: &PathBuf) -> Result { - 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 { + Ok(Mmap::map(&File::open(path)?)?) } pub(crate) fn make_mmap_stdin() -> Result { diff --git a/src/main.rs b/src/main.rs index a0e4bb4..3f00f4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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())) },