Skip to content

Commit 5bc34cb

Browse files
committed
Fix WriteFmtFuture not taking into account already written bytes (#964)
1 parent d395607 commit 5bc34cb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/io/write/write_fmt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct WriteFmtFuture<'a, T: Unpin + ?Sized> {
1111
pub(crate) writer: &'a mut T,
1212
pub(crate) res: Option<io::Result<Vec<u8>>>,
1313
pub(crate) buffer: Option<Vec<u8>>,
14-
pub(crate) amt: u64,
14+
pub(crate) amt: usize,
1515
}
1616

1717
impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
@@ -37,15 +37,15 @@ impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
3737

3838
// Copy the data from the buffer into the writer until it's done.
3939
loop {
40-
if *amt == buffer.len() as u64 {
40+
if *amt == buffer.len() {
4141
futures_core::ready!(Pin::new(&mut **writer).poll_flush(cx))?;
4242
return Poll::Ready(Ok(()));
4343
}
44-
let i = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, buffer))?;
44+
let i = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, &buffer[*amt..]))?;
4545
if i == 0 {
4646
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
4747
}
48-
*amt += i as u64;
48+
*amt += i;
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)