Skip to content

Commit b21f732

Browse files
committed
fix lints
1 parent 94beb9b commit b21f732

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl UnalignedF32Slice {
5757
/// Creates an unaligned slice of f32 wrapper from a slice of bytes.
5858
pub fn from_bytes(bytes: &[u8]) -> Result<&Self, SizeMismatch> {
5959
if bytes.len() % size_of::<f32>() == 0 {
60+
// safety: `UnalignedF32Slice` is transparent
6061
Ok(unsafe { transmute(bytes) })
6162
} else {
6263
Err(SizeMismatch)

src/parallel.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl<'a, DE: BytesEncode<'a>> TmpNodes<DE> {
7979
/// Converts it into a readers to read the nodes.
8080
pub fn into_bytes_reader(self) -> Result<TmpNodesReader> {
8181
let file = self.file.into_inner().map_err(|iie| iie.into_error())?;
82+
// safety: No one should move our files around
8283
let mmap = unsafe { Mmap::map(&file)? };
8384
#[cfg(unix)]
8485
mmap.advise(memmap2::Advice::Sequential)?;
@@ -224,6 +225,10 @@ impl<'t, D: Distance> ImmutableLeafs<'t, D> {
224225
Some(ptr) => *ptr,
225226
None => return Ok(None),
226227
};
228+
229+
// safety:
230+
// - ptr: The pointer comes from LMDB. Since the database cannot be written to, it is still valid.
231+
// - len: All the items share the same dimensions and are the same size
227232
let bytes = unsafe { slice::from_raw_parts(ptr, len) };
228233
NodeCodec::bytes_decode(bytes).map_err(heed::Error::Decoding).map(|node| node.leaf())
229234
}
@@ -326,6 +331,9 @@ impl<'t, D: Distance> ImmutableTrees<'t, D> {
326331
None => return Ok(None),
327332
};
328333

334+
// safety:
335+
// - ptr: The pointer comes from LMDB. Since the database cannot be written to, it is still valid.
336+
// - len: The len cannot change either
329337
let bytes = unsafe { slice::from_raw_parts(ptr, len) };
330338
NodeCodec::bytes_decode(bytes).map_err(heed::Error::Decoding).map(Some)
331339
}

0 commit comments

Comments
 (0)