fix clippy

Signed-off-by: Yuchen Liang <yuchen@neon.tech>
This commit is contained in:
Yuchen Liang
2024-11-12 15:59:24 +00:00
parent d6d8a16dbc
commit ffd88ede38
2 changed files with 5 additions and 2 deletions

View File

@@ -410,7 +410,7 @@ mod tests {
}
let file_contents = std::fs::read(file.buffered_writer.as_inner().path()).unwrap();
assert!(file_contents == &content[0..cap] || file_contents == &content[0..cap * 2]);
assert!(file_contents == content[0..cap] || file_contents == content[0..cap * 2]);
let maybe_flushed_buffer_contents = file.buffered_writer.inspect_maybe_flushed().unwrap();
assert_eq!(maybe_flushed_buffer_contents, &content[cap..cap * 2]);

View File

@@ -141,6 +141,7 @@ impl<A: Alignment> AlignedBufferMut<A> {
let cnt = extend.len();
self.reserve(cnt);
// SAFETY: we already reserved additional `cnt` bytes, safe to perform memcpy.
unsafe {
let dst = self.spare_capacity_mut();
// Reserved above
@@ -148,7 +149,7 @@ impl<A: Alignment> AlignedBufferMut<A> {
core::ptr::copy_nonoverlapping(extend.as_ptr(), dst.as_mut_ptr().cast(), cnt);
}
// SAFETY: We do have at least `cnt` bytes remaining before advance.
unsafe {
bytes::BufMut::advance_mut(self, cnt);
}
@@ -156,6 +157,8 @@ impl<A: Alignment> AlignedBufferMut<A> {
#[inline]
fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<u8>] {
// SAFETY: we guarantees that the `Self::capacity()` bytes from
// `Self::as_mut_ptr()` are allocated.
unsafe {
let ptr = self.as_mut_ptr().add(self.len());
let len = self.capacity() - self.len();