address review: remove OwnedBuf impl

This commit is contained in:
mox692 2025-09-11 12:28:34 +09:00
parent 4fc67646be
commit a3ea51673a
3 changed files with 3 additions and 19 deletions

View File

@ -56,7 +56,7 @@ async fn write_uring(path: &Path, mut buf: OwnedBuf) -> io::Result<()> {
.expect("unexpected in-flight operation detected")
.into();
let total: usize = buf.len();
let total: usize = buf.as_ref().len();
let mut offset: usize = 0;
while offset < total {
// There is a cap on how many bytes we can write in a single uring write operation.

View File

@ -38,13 +38,13 @@ impl Op<Write> {
file_offset: u64,
) -> io::Result<Self> {
// Check if `buf_offset` stays in bounds of the allocation
debug_assert!(buf_offset + len as usize <= buf.len());
debug_assert!(buf_offset + len as usize <= buf.as_ref().len());
// SAFETY:
// - `buf_offset` stays in bounds of the allocation.
// - `buf` is derived from an actual allocation, and the entire memory
// range is in bounds of that allocation.
let ptr = unsafe { buf.as_ptr().add(buf_offset) };
let ptr = unsafe { buf.as_ref().as_ptr().add(buf_offset) };
let sqe = opcode::Write::new(types::Fd(fd.as_raw_fd()), ptr, len)
.offset(file_offset)

View File

@ -7,22 +7,6 @@ pub(crate) enum OwnedBuf {
Bytes(bytes::Bytes),
}
impl OwnedBuf {
cfg_tokio_uring! {
pub(crate) fn len(&self) -> usize {
match self {
Self::Vec(vec) => vec.len(),
#[cfg(feature = "io-util")]
Self::Bytes(bytes) => bytes.len(),
}
}
pub(crate) fn as_ptr(&self) -> *const u8 {
self.as_ref().as_ptr()
}
}
}
impl AsRef<[u8]> for OwnedBuf {
fn as_ref(&self) -> &[u8] {
match self {