mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-19 20:13:51 +00:00
comments
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
This commit is contained in:
parent
570dedd712
commit
f3eba1fb48
2 changed files with 5 additions and 2 deletions
|
@ -234,6 +234,9 @@ extension_trait! {
|
||||||
where
|
where
|
||||||
Self: Unpin,
|
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<Vec<u8>>` and pass that to the Future.
|
||||||
|
// Doing an owned conversion saves us from juggling references.
|
||||||
let mut string = String::new();
|
let mut string = String::new();
|
||||||
let res = std::fmt::write(&mut string, fmt)
|
let res = std::fmt::write(&mut string, fmt)
|
||||||
.map(|_| string.into_bytes())
|
.map(|_| string.into_bytes())
|
||||||
|
|
|
@ -17,7 +17,6 @@ impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
|
||||||
type Output = io::Result<()>;
|
type Output = io::Result<()>;
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
|
|
||||||
// Process the interal Result the first time we run.
|
// Process the interal Result the first time we run.
|
||||||
if self.buffer.is_none() {
|
if self.buffer.is_none() {
|
||||||
match self.res.take().unwrap() {
|
match self.res.take().unwrap() {
|
||||||
|
@ -26,15 +25,16 @@ impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the types from the future.
|
||||||
let Self { writer, amt, buffer, .. } = &mut *self;
|
let Self { writer, amt, buffer, .. } = &mut *self;
|
||||||
let mut buffer = buffer.as_mut().unwrap();
|
let mut buffer = buffer.as_mut().unwrap();
|
||||||
|
|
||||||
|
// Copy the data from the buffer into the writer until it's done.
|
||||||
loop {
|
loop {
|
||||||
if buffer.is_empty() {
|
if buffer.is_empty() {
|
||||||
futures_core::ready!(Pin::new(&mut **writer).poll_flush(cx))?;
|
futures_core::ready!(Pin::new(&mut **writer).poll_flush(cx))?;
|
||||||
return Poll::Ready(Ok(()));
|
return Poll::Ready(Ok(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let i = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, &mut buffer))?;
|
let i = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, &mut buffer))?;
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
|
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
|
||||||
|
|
Loading…
Reference in a new issue