base_scheduler/io_buf.rs
1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use crate::BufferSlice;
5use std::ops::RangeBounds;
6
7/// Owned, initialized storage suitable for completion-based I/O.
8///
9/// # Safety
10/// `as_ref()` must always expose the same initialized allocation and length while an operation owns this value, even if the value moves. The allocation must remain alive until this value is dropped, and must not be mutated through another owner during an operation. Implementations must not expose inline storage whose address changes when the owner moves.
11pub unsafe trait IoBuf: AsRef<[u8]> + Send + 'static {
12 /// Limit an operation to an owned range without copying its bytes. Panics if the range is outside the initialized buffer.
13 fn slice(self, range: impl RangeBounds<usize>) -> BufferSlice<Self>
14 where
15 Self: Sized,
16 {
17 BufferSlice::new(self, range)
18 }
19}
20
21// SAFETY: Both owners retain a stable heap allocation as they move. Exclusive ownership prevents mutation by another owner while an operation holds them.
22unsafe impl IoBuf for Vec<u8> {}
23unsafe impl IoBuf for Box<[u8]> {}