rustfmt all examples

staging
Florian Gilcher 5 years ago
parent 9370cd3298
commit dfd520c778
No known key found for this signature in database
GPG Key ID: E7B51D33F8EBF61B

@ -1,29 +1,26 @@
use std::time::Duration; use std::time::Duration;
use async_std::{ use async_std::{io, net::TcpStream, prelude::*, task};
prelude::*,
task,
io,
net::TcpStream,
};
async fn get() -> io::Result<Vec<u8>> { async fn get() -> io::Result<Vec<u8>> {
let mut stream = TcpStream::connect("example.com:80").await?; let mut stream = TcpStream::connect("example.com:80").await?;
stream.write_all(b"GET /index.html HTTP/1.0\r\n\r\n").await?; stream
.write_all(b"GET /index.html HTTP/1.0\r\n\r\n")
.await?;
let mut buf = vec![]; let mut buf = vec![];
io::timeout(Duration::from_secs(5), async { io::timeout(Duration::from_secs(5), async {
stream.read_to_end(&mut buf).await?; stream.read_to_end(&mut buf).await?;
Ok(buf) Ok(buf)
}).await })
.await
} }
fn main() { fn main() {
task::block_on(async { task::block_on(async {
let raw_response = get().await.expect("request"); let raw_response = get().await.expect("request");
let response = String::from_utf8(raw_response) let response = String::from_utf8(raw_response).expect("utf8 conversion");
.expect("utf8 conversion");
println!("received: {}", response); println!("received: {}", response);
}); });
} }

Loading…
Cancel
Save