From c1d7d708d4f0fc51cdada92b057be916d555e7b9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 17 Aug 2020 11:53:01 +0200 Subject: [PATCH] remove map_struct helper if we ever need this it should be marked as unsafe! Signed-off-by: Wolfgang Bumiller --- src/tools.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/tools.rs b/src/tools.rs index 8792bf0c..1b9d35a8 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -62,32 +62,6 @@ pub trait BufferedRead { fn buffered_read(&mut self, offset: u64) -> Result<&[u8], Error>; } -/// Directly map a type into a binary buffer. This is mostly useful -/// for reading structured data from a byte stream (file). You need to -/// make sure that the buffer location does not change, so please -/// avoid vec resize while you use such map. -/// -/// This function panics if the buffer is not large enough. -pub fn map_struct(buffer: &[u8]) -> Result<&T, Error> { - if buffer.len() < ::std::mem::size_of::() { - bail!("unable to map struct - buffer too small"); - } - Ok(unsafe { &*(buffer.as_ptr() as *const T) }) -} - -/// Directly map a type into a mutable binary buffer. This is mostly -/// useful for writing structured data into a byte stream (file). You -/// need to make sure that the buffer location does not change, so -/// please avoid vec resize while you use such map. -/// -/// This function panics if the buffer is not large enough. -pub fn map_struct_mut(buffer: &mut [u8]) -> Result<&mut T, Error> { - if buffer.len() < ::std::mem::size_of::() { - bail!("unable to map struct - buffer too small"); - } - Ok(unsafe { &mut *(buffer.as_ptr() as *mut T) }) -} - /// Split a file into equal sized chunks. The last chunk may be /// smaller. Note: We cannot implement an `Iterator`, because iterators /// cannot return a borrowed buffer ref (we want zero-copy)