More explicit examples

This commit is contained in:
Stjepan Glavina 2020-02-04 11:41:48 +01:00
parent e66cb48ec9
commit ba4c816545
2 changed files with 7 additions and 4 deletions

View File

@ -6,6 +6,8 @@
//! $ nc localhost 8080
//! ```
use std::net::TcpStream;
use futures::executor::block_on;
use futures::io;
use futures::prelude::*;
@ -13,7 +15,7 @@ use smol::Async;
fn main() -> io::Result<()> {
block_on(async {
let mut stream = Async::connect("www.example.com:80").await?;
let mut stream = Async::<TcpStream>::connect("www.example.com:80").await?;
stream
.write_all(b"GET / HTTP/1.0\r\nHost: example.com\r\n\r\n")
.await?;

View File

@ -6,7 +6,7 @@
//! $ nc localhost 8080
//! ```
use std::net::TcpStream;
use std::net::{TcpListener, TcpStream};
use futures::executor::block_on;
use futures::io;
@ -14,12 +14,13 @@ use smol::Async;
async fn process(mut stream: Async<TcpStream>) -> io::Result<()> {
println!("Peer: {}", stream.source().peer_addr()?);
io::copy(stream.clone(), &mut stream).await
io::copy(stream.clone(), &mut stream).await?;
Ok(())
}
fn main() -> io::Result<()> {
block_on(async {
let listener = Async::bind("127.0.0.1:8080")?;
let listener = Async::<TcpListener>::bind("127.0.0.1:8080")?;
println!("Local: {}", listener.source().local_addr()?);
loop {