File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed
Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 11use std:: time:: Duration ;
22
3- use async_std:: {
4- prelude:: * ,
5- task,
6- io,
7- net:: TcpStream ,
8- } ;
3+ use async_std:: { io, net:: TcpStream , prelude:: * , task} ;
94
105async fn get ( ) -> io:: Result < Vec < u8 > > {
116 let mut stream = TcpStream :: connect ( "example.com:80" ) . await ?;
12- stream. write_all ( b"GET /index.html HTTP/1.0\r \n \r \n " ) . await ?;
7+ stream
8+ . write_all ( b"GET /index.html HTTP/1.0\r \n \r \n " )
9+ . await ?;
1310
1411 let mut buf = vec ! [ ] ;
1512
1613 io:: timeout ( Duration :: from_secs ( 5 ) , async {
1714 stream. read_to_end ( & mut buf) . await ?;
1815 Ok ( buf)
19- } ) . await
16+ } )
17+ . await
2018}
2119
2220fn main ( ) {
2321 task:: block_on ( async {
2422 let raw_response = get ( ) . await . expect ( "request" ) ;
25- let response = String :: from_utf8 ( raw_response)
26- . expect ( "utf8 conversion" ) ;
23+ let response = String :: from_utf8 ( raw_response) . expect ( "utf8 conversion" ) ;
2724 println ! ( "received: {}" , response) ;
2825 } ) ;
2926}
You can’t perform that action at this time.
0 commit comments