Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ea6f9ce
refactor(buf): whole buf
George-Miao Dec 1, 2025
34d9cf0
fix(driver): adopt new buf
George-Miao Dec 1, 2025
e2fd708
fix(buf): typo
George-Miao Dec 1, 2025
4a9cc7b
fix(buf): slice iter oob
George-Miao Dec 1, 2025
b2b6071
fix(driver): typo
George-Miao Dec 1, 2025
beecde6
fix(buf): inconsistent doc comment
George-Miao Dec 1, 2025
ed00564
fix(buf): smallvec impl
George-Miao Dec 1, 2025
43482c7
fix(driver): typo
George-Miao Dec 1, 2025
e86f0de
feat(buf): make Uninit<T> deref to [MaybeUninit<u8>]
George-Miao Dec 1, 2025
af9e49a
fix(driver): iocp
George-Miao Dec 1, 2025
e988980
fix(driver): clippy
George-Miao Dec 1, 2025
777189c
fix(driver): from_slice is never used
George-Miao Dec 1, 2025
8188e70
fix: fmt
George-Miao Dec 1, 2025
d0a4b36
fix: tests
George-Miao Dec 2, 2025
7f29539
fix(driver): aio fn requires unsafe block
George-Miao Dec 2, 2025
968b2a7
feat(buf): make slice begin at uninit possible
George-Miao Dec 2, 2025
cb5fa2f
feat(driver): use WSABUF from windows_sys
George-Miao Dec 2, 2025
72af001
fix(buf): slice
George-Miao Dec 2, 2025
48e35a9
docs(buf): fix for IoBufferMut::len
George-Miao Dec 2, 2025
be81349
feat(buf): doc test
George-Miao Dec 2, 2025
63f288f
refactor(buf): rename to into_raw_parts
George-Miao Dec 2, 2025
c7b1661
fix: grammar
George-Miao Dec 2, 2025
a249648
fix(buf): capacity of vec slice
George-Miao Dec 2, 2025
d39e8da
Merge branch 'master' into refactor/io
George-Miao Dec 2, 2025
472e43a
refactor(driver): remove SysSliceMut
George-Miao Dec 3, 2025
266ccb4
refactor: make `IoBuf{,mut}` safe
George-Miao Dec 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(buf): make slice begin at uninit possible
  • Loading branch information
George-Miao committed Dec 2, 2025
commit 968b2a7922e2d505a4ca73e649cee9938434bdba
4 changes: 0 additions & 4 deletions compio-buf/src/io_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,12 @@ pub unsafe trait IoBuf: 'static {
{
use std::ops::Bound;

let len = self.buf_len();

let begin = match range.start_bound() {
Bound::Included(&n) => n,
Bound::Excluded(&n) => n + 1,
Bound::Unbounded => 0,
};

assert!(begin <= len);

let end = match range.end_bound() {
Bound::Included(&n) => Some(n.checked_add(1).expect("out of range")),
Bound::Excluded(&n) => Some(n),
Expand Down
25 changes: 25 additions & 0 deletions compio-buf/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ impl<T: IoBuf> Deref for Slice<T> {

fn deref(&self) -> &Self::Target {
let bytes = self.buffer.as_slice();
if self.begin >= bytes.len() {
return &[];
}
let end = self.end.unwrap_or(bytes.len()).min(bytes.len());
&bytes[self.begin..end]
}
Expand All @@ -72,6 +75,9 @@ impl<T: IoBuf> Deref for Slice<T> {
impl<T: IoBufMut> DerefMut for Slice<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
let begin = self.begin();
if begin >= self.buffer.buf_len() {
return &mut [];
}
let buf_len = self.buffer.buf_len();
let end = self.end().unwrap_or(buf_len).min(buf_len);
let ptr = unsafe { self.buffer.buffer() }.as_ptr();
Expand Down Expand Up @@ -299,3 +305,22 @@ impl<T: IoVectoredBufMut> IoVectoredBufMut for VectoredSliceMut<T> {
self.buf.capacity_of(idx + self.idx)
}
}

#[test]
fn test_slice() {
let buf = b"hello world";
let slice = buf.slice(6..);
assert_eq!(slice.as_slice(), b"world");

let slice = buf.slice(..5);
assert_eq!(slice.as_slice(), b"hello");

let slice = buf.slice(3..8);
assert_eq!(slice.as_slice(), b"lo wo");

let slice = buf.slice(..);
assert_eq!(slice.as_slice(), b"hello world");

let slice = buf.slice(12..);
assert_eq!(slice.as_slice(), b"");
}
Loading