Skip to content

Commit d2c73db

Browse files
committed
fix(io): read_exact should use the capacity
1 parent 49eeafa commit d2c73db

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

compio-buf/src/io_buf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ pub trait SetBufInit {
594594
///
595595
/// # Safety
596596
///
597-
/// `len` should be less or equal than `buf_capacity() - buf_len()`.
597+
/// `len` should be less or equal than `buf_capacity()`.
598598
unsafe fn set_buf_init(&mut self, len: usize);
599599
}
600600

compio-io/src/read/ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub trait AsyncReadExt: AsyncRead {
147147

148148
/// Read the exact number of bytes required to fill the buf.
149149
async fn read_exact<T: IoBufMut>(&mut self, mut buf: T) -> BufResult<usize, T> {
150-
loop_read_exact!(buf, buf.buf_capacity() - buf.buf_len(), read, loop self.read(buf.slice(read..)));
150+
loop_read_exact!(buf, buf.buf_capacity(), read, loop self.read(buf.slice(read..)));
151151
}
152152

153153
/// Read all bytes until underlying reader reaches `EOF`.
@@ -221,7 +221,7 @@ pub trait AsyncReadAtExt: AsyncReadAt {
221221
async fn read_exact_at<T: IoBufMut>(&self, mut buf: T, pos: u64) -> BufResult<usize, T> {
222222
loop_read_exact!(
223223
buf,
224-
buf.buf_capacity() - buf.buf_len(),
224+
buf.buf_capacity(),
225225
read,
226226
loop self.read_at(buf.slice(read..), pos + read as u64)
227227
);

compio-io/tests/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl AsyncReadAt for RepeatOne {
220220
async fn read_exact() {
221221
let mut src = RepeatOne(114);
222222

223-
let (len, buf) = src.read_exact(Vec::with_capacity(5)).await.unwrap();
223+
let (len, buf) = src.read_exact(vec![0; 5]).await.unwrap();
224224
assert_eq!(len, 5);
225225
assert_eq!(buf, [114; 5]);
226226

0 commit comments

Comments
 (0)