From f3eba1fb48641cc7c671c7cdd0e4683888714a13 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Sun, 13 Oct 2019 01:34:13 +0200 Subject: [PATCH] comments Signed-off-by: Yoshua Wuyts --- src/io/write/mod.rs | 3 +++ src/io/write/write_fmt.rs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/io/write/mod.rs b/src/io/write/mod.rs index 169c9e1e..bb03d901 100644 --- a/src/io/write/mod.rs +++ b/src/io/write/mod.rs @@ -234,6 +234,9 @@ extension_trait! { where Self: Unpin, { + // In order to not have to implement an async version of `fmt` including private types + // and all, we convert `Arguments` to a `Result>` and pass that to the Future. + // Doing an owned conversion saves us from juggling references. let mut string = String::new(); let res = std::fmt::write(&mut string, fmt) .map(|_| string.into_bytes()) diff --git a/src/io/write/write_fmt.rs b/src/io/write/write_fmt.rs index 9c8187ab..bd2dd673 100644 --- a/src/io/write/write_fmt.rs +++ b/src/io/write/write_fmt.rs @@ -17,7 +17,6 @@ impl Future for WriteFmtFuture<'_, T> { type Output = io::Result<()>; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - // Process the interal Result the first time we run. if self.buffer.is_none() { match self.res.take().unwrap() { @@ -26,15 +25,16 @@ impl Future for WriteFmtFuture<'_, T> { }; } + // Get the types from the future. let Self { writer, amt, buffer, .. } = &mut *self; let mut buffer = buffer.as_mut().unwrap(); + // Copy the data from the buffer into the writer until it's done. loop { if buffer.is_empty() { futures_core::ready!(Pin::new(&mut **writer).poll_flush(cx))?; return Poll::Ready(Ok(())); } - let i = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, &mut buffer))?; if i == 0 { return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));