Formatting

pull/13/head
Stjepan Glavina 5 years ago
parent fdf0e3ad0f
commit caf50e69cf

@ -4,7 +4,7 @@
use std::env::args; use std::env::args;
use async_std::{fs, io, prelude::*, task}; use async_std::{fs::File, io, prelude::*, task};
const LEN: usize = 4 * 1024 * 1024; // 4 Mb const LEN: usize = 4 * 1024 * 1024; // 4 Mb
@ -12,7 +12,7 @@ fn main() -> io::Result<()> {
let path = args().nth(1).expect("missing path argument"); let path = args().nth(1).expect("missing path argument");
task::block_on(async { task::block_on(async {
let mut file = fs::File::open(&path).await?; let mut file = File::open(&path).await?;
let mut stdout = io::stdout(); let mut stdout = io::stdout();
let mut buf = vec![0u8; LEN]; let mut buf = vec![0u8; LEN];
@ -23,7 +23,6 @@ fn main() -> io::Result<()> {
// If this is the end of file, clean up and return. // If this is the end of file, clean up and return.
if n == 0 { if n == 0 {
stdout.flush().await?; stdout.flush().await?;
file.close().await?;
return Ok(()); return Ok(());
} }

@ -14,11 +14,11 @@
#![feature(async_await)] #![feature(async_await)]
use async_std::{io, net, prelude::*, task}; use async_std::{io, net::TcpStream, prelude::*, task};
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
task::block_on(async { task::block_on(async {
let mut stream = net::TcpStream::connect("127.0.0.1:8080").await?; let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
println!("Connected to {}", &stream.peer_addr()?); println!("Connected to {}", &stream.peer_addr()?);
let msg = "hello world"; let msg = "hello world";

@ -8,9 +8,10 @@
#![feature(async_await)] #![feature(async_await)]
use async_std::{io, net, prelude::*, task}; use async_std::net::{TcpListener, TcpStream};
use async_std::{io, prelude::*, task};
async fn process(stream: net::TcpStream) -> io::Result<()> { async fn process(stream: TcpStream) -> io::Result<()> {
println!("Accepted from: {}", stream.peer_addr()?); println!("Accepted from: {}", stream.peer_addr()?);
let (reader, writer) = &mut (&stream, &stream); let (reader, writer) = &mut (&stream, &stream);
@ -21,7 +22,7 @@ async fn process(stream: net::TcpStream) -> io::Result<()> {
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
task::block_on(async { task::block_on(async {
let listener = net::TcpListener::bind("127.0.0.1:8080").await?; let listener = TcpListener::bind("127.0.0.1:8080").await?;
println!("Listening on {}", listener.local_addr()?); println!("Listening on {}", listener.local_addr()?);
let mut incoming = listener.incoming(); let mut incoming = listener.incoming();

@ -14,11 +14,11 @@
#![feature(async_await)] #![feature(async_await)]
use async_std::{io, net, task}; use async_std::{io, net::UdpSocket, task};
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
task::block_on(async { task::block_on(async {
let socket = net::UdpSocket::bind("127.0.0.1:8081").await?; let socket = UdpSocket::bind("127.0.0.1:8081").await?;
println!("Listening on {}", socket.local_addr()?); println!("Listening on {}", socket.local_addr()?);
let msg = "hello world"; let msg = "hello world";

@ -8,11 +8,11 @@
#![feature(async_await)] #![feature(async_await)]
use async_std::{io, net, task}; use async_std::{io, net::UdpSocket, task};
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
task::block_on(async { task::block_on(async {
let socket = net::UdpSocket::bind("127.0.0.1:8080").await?; let socket = UdpSocket::bind("127.0.0.1:8080").await?;
let mut buf = vec![0u8; 1024]; let mut buf = vec![0u8; 1024];
println!("Listening on {}", socket.local_addr()?); println!("Listening on {}", socket.local_addr()?);

Loading…
Cancel
Save