File tree 2 files changed +5
-2
lines changed
2 files changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,9 @@ extension_trait! {
234
234
where
235
235
Self : Unpin ,
236
236
{
237
+ // In order to not have to implement an async version of `fmt` including private types
238
+ // and all, we convert `Arguments` to a `Result<Vec<u8>>` and pass that to the Future.
239
+ // Doing an owned conversion saves us from juggling references.
237
240
let mut string = String :: new( ) ;
238
241
let res = std:: fmt:: write( & mut string, fmt)
239
242
. map( |_| string. into_bytes( ) )
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
17
17
type Output = io:: Result < ( ) > ;
18
18
19
19
fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
20
-
21
20
// Process the interal Result the first time we run.
22
21
if self . buffer . is_none ( ) {
23
22
match self . res . take ( ) . unwrap ( ) {
@@ -26,15 +25,16 @@ impl<T: Write + Unpin + ?Sized> Future for WriteFmtFuture<'_, T> {
26
25
} ;
27
26
}
28
27
28
+ // Get the types from the future.
29
29
let Self { writer, amt, buffer, .. } = & mut * self ;
30
30
let mut buffer = buffer. as_mut ( ) . unwrap ( ) ;
31
31
32
+ // Copy the data from the buffer into the writer until it's done.
32
33
loop {
33
34
if buffer. is_empty ( ) {
34
35
futures_core:: ready!( Pin :: new( & mut * * writer) . poll_flush( cx) ) ?;
35
36
return Poll :: Ready ( Ok ( ( ) ) ) ;
36
37
}
37
-
38
38
let i = futures_core:: ready!( Pin :: new( & mut * * writer) . poll_write( cx, & mut buffer) ) ?;
39
39
if i == 0 {
40
40
return Poll :: Ready ( Err ( io:: ErrorKind :: WriteZero . into ( ) ) ) ;
You can’t perform that action at this time.
0 commit comments