monoio/buf/
mod.rs

1//! Utilities for working with buffers.
2//!
3//! `io_uring` APIs require passing ownership of buffers to the runtime. The
4//! crate defines [`IoBuf`] and [`IoBufMut`] traits which are implemented by
5//! buffer types that respect the `io_uring` contract.
6// Heavily borrowed from tokio-uring.
7// Copyright (c) 2021 Tokio-uring Contributors, licensed under the MIT license.
8
9mod io_buf;
10pub use io_buf::{IoBuf, IoBufMut};
11
12mod io_vec_buf;
13pub use io_vec_buf::{IoVecBuf, IoVecBufMut, VecBuf};
14
15mod slice;
16pub use slice::{IoVecWrapper, IoVecWrapperMut, Slice, SliceMut};
17
18mod raw_buf;
19pub use raw_buf::{RawBuf, RawBufVectored};
20
21mod vec_wrapper;
22pub(crate) use vec_wrapper::{read_vec_meta, write_vec_meta, IoVecMeta};
23
24mod msg;
25pub use msg::{MsgBuf, MsgBufMut, MsgMeta};
26
27pub(crate) fn deref(buf: &impl IoBuf) -> &[u8] {
28    // Safety: the `IoBuf` trait is marked as unsafe and is expected to be
29    // implemented correctly.
30    unsafe { std::slice::from_raw_parts(buf.read_ptr(), buf.bytes_init()) }
31}