Expand description
Binary data trait for compio async IO.
compio uses io_uring/IOCP for async IO, which requires buffer ownership transfer. The kernel holds the buffer during IO, so we must pass owned data, not references.
§compio IoBuf constraint
compio requires IoBuf trait for async write. Types that impl IoBuf:
Vec<u8>,Box<[u8]>,&'static [u8],&'static strRc<[u8]>,Arc<[u8]>(zero-copy, compio native support)Bytes(withbytesfeature)
§Bin trait
This trait bridges various input types to compio’s ownership model:
as_slice(): for sync operations (CRC calc, inline write)io(): transfer ownership to kernel, returnsSelf::Io: IoBuf
§Zero-copy Table
| Type | Io | Note |
|---|---|---|
Vec<u8>, Box<[u8]> | self | zero-copy |
Rc<[u8]>, Arc<[u8]> | self | zero-copy (compio impl) |
Bytes | self | zero-copy |
&Rc, &Arc, &Bytes | clone | O(1) ref-count +1 |
String | Vec<u8> | into_bytes() |
&[u8], &str, &[u8; N] | Box<[u8]> | copy |
Cow<[u8]>, Cow<str> | Vec<u8> | into_owned |
用于 compio 异步 IO 的二进制数据 trait。
compio 使用 io_uring/IOCP 实现异步 IO,需要转移缓冲区所有权。 内核在 IO 期间持有缓冲区,因此必须传递拥有所有权的数据,而非引用。
§compio IoBuf 约束
compio 异步写入需要 IoBuf trait。实现了 IoBuf 的类型:
Vec<u8>,Box<[u8]>,&'static [u8],&'static strRc<[u8]>,Arc<[u8]>(零拷贝,compio 原生支持)Bytes(需bytesfeature)
§Bin trait
此 trait 将各种输入类型桥接到 compio 的所有权模型:
as_slice(): 用于同步操作(CRC 计算、内联写入)io(): 将所有权转移给内核,返回Self::Io: IoBuf
§零拷贝表
| 类型 | Io | 说明 |
|---|---|---|
Vec<u8>, Box<[u8]> | self | 零拷贝 |
Rc<[u8]>, Arc<[u8]> | self | 零拷贝(compio 实现) |
Bytes | self | 零拷贝 |
&Rc, &Arc, &Bytes | clone | O(1) 引用计数 +1 |
String | Vec<u8> | into_bytes() |
&[u8], &str, &[u8; N] | Box<[u8]> | 拷贝 |
Cow<[u8]>, Cow<str> | Vec<u8> | into_owned |
Traits§
- Bin
- Binary data trait for async IO / 异步 IO 二进制数据 trait