File tree Expand file tree Collapse file tree 5 files changed +20
-16
lines changed Expand file tree Collapse file tree 5 files changed +20
-16
lines changed Original file line number Diff line number Diff line change 11use futures:: select;
22use futures:: FutureExt ;
3+ use std:: io:: { self , BufReader as StdBufReader , BufRead } ;
34
45use async_std:: {
5- io:: { stdin , BufReader } ,
6+ io:: { BufReader } ,
67 net:: { TcpStream , ToSocketAddrs } ,
78 prelude:: * ,
9+ stream,
810 task,
911} ;
1012
@@ -20,8 +22,9 @@ async fn try_main(addr: impl ToSocketAddrs) -> Result<()> {
2022 let reader = BufReader :: new ( reader) ;
2123 let mut lines_from_server = futures:: StreamExt :: fuse ( reader. lines ( ) ) ;
2224
23- let stdin = BufReader :: new ( stdin ( ) ) ;
24- let mut lines_from_stdin = futures:: StreamExt :: fuse ( stdin. lines ( ) ) ;
25+ let stdin = StdBufReader :: new ( io:: stdin ( ) ) ;
26+ let mut lines_from_stdin = stream:: from_iter ( stdin. lines ( ) ) ;
27+
2528 loop {
2629 select ! {
2730 line = lines_from_server. next( ) . fuse( ) => match line {
Original file line number Diff line number Diff line change 11//! Prints a file given as an argument to stdout.
22
33use std:: env:: args;
4+ use std:: io:: Write ;
45
56use async_std:: fs:: File ;
67use async_std:: io;
@@ -14,7 +15,7 @@ fn main() -> io::Result<()> {
1415
1516 task:: block_on ( async {
1617 let mut file = File :: open ( & path) . await ?;
17- let mut stdout = io:: stdout ( ) ;
18+ let mut stdout = std :: io:: stdout ( ) ;
1819 let mut buf = vec ! [ 0u8 ; LEN ] ;
1920
2021 loop {
@@ -23,12 +24,12 @@ fn main() -> io::Result<()> {
2324
2425 // If this is the end of file, clean up and return.
2526 if n == 0 {
26- stdout. flush ( ) . await ?;
27+ stdout. flush ( ) ?;
2728 return Ok ( ( ) ) ;
2829 }
2930
3031 // Write the buffer into stdout.
31- stdout. write_all ( & buf[ ..n] ) . await ?;
32+ stdout. write_all ( & buf[ ..n] ) ?;
3233 }
3334 } )
3435}
Original file line number Diff line number Diff line change 11//! Echoes lines read on stdin to stdout.
22
3+ use std:: io:: Write ;
34use async_std:: io;
4- use async_std:: prelude:: * ;
55use async_std:: task;
66
77fn main ( ) -> io:: Result < ( ) > {
88 task:: block_on ( async {
9- let stdin = io:: stdin ( ) ;
10- let mut stdout = io:: stdout ( ) ;
9+ let stdin = std :: io:: stdin ( ) ;
10+ let mut stdout = std :: io:: stdout ( ) ;
1111 let mut line = String :: new ( ) ;
1212
1313 loop {
1414 // Read a line from stdin.
15- let n = stdin. read_line ( & mut line) . await ?;
15+ let n = stdin. read_line ( & mut line) ?;
1616
1717 // If this is the end of stdin, return.
1818 if n == 0 {
1919 return Ok ( ( ) ) ;
2020 }
2121
2222 // Write the line to stdout.
23- stdout. write_all ( line. as_bytes ( ) ) . await ?;
24- stdout. flush ( ) . await ?;
23+ stdout. write_all ( line. as_bytes ( ) ) ?;
24+ stdout. flush ( ) ?;
2525 line. clear ( ) ;
2626 }
2727 } )
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ use async_std::task;
88fn main ( ) -> io:: Result < ( ) > {
99 // This async scope times out after 5 seconds.
1010 task:: block_on ( io:: timeout ( Duration :: from_secs ( 5 ) , async {
11- let stdin = io:: stdin ( ) ;
11+ let stdin = std :: io:: stdin ( ) ;
1212
1313 // Read a line from the standard input and display it.
1414 let mut line = String :: new ( ) ;
15- stdin. read_line ( & mut line) . await ?;
15+ stdin. read_line ( & mut line) ?;
1616 dbg ! ( line) ;
1717
1818 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ use async_std::task;
88fn io_timeout_timedout ( ) {
99 task:: block_on ( async {
1010 io:: timeout ( Duration :: from_secs ( 1 ) , async {
11- let stdin = io:: stdin ( ) ;
11+ let stdin = std :: io:: stdin ( ) ;
1212 let mut line = String :: new ( ) ;
13- let _n = stdin. read_line ( & mut line) . await ?;
13+ let _n = stdin. read_line ( & mut line) ?;
1414 Ok ( ( ) )
1515 } )
1616 . await
You can’t perform that action at this time.
0 commit comments