Merge pull request #112 from async-rs/fix-101

Import HashMap visibly in the tutorial
This commit is contained in:
Florian Gilcher 2019-08-26 16:04:33 -07:00 committed by GitHub
commit d501bf6849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View file

@ -6,9 +6,8 @@ In `async-std`, the [`tasks`][tasks] module is responsible for this. The simples
```rust,edition2018
# extern crate async_std;
# use async_std::{fs::File, io::Read, task};
# use std::io;
#
use async_std::{io, task, fs::File, io::Read};
async fn read_file(path: &str) -> Result<String, io::Error> {
let mut file = File::open(path).await?;
let mut contents = String::new();

View file

@ -74,7 +74,7 @@ async fn client(mut broker: Sender<Event>, stream: TcpStream) -> Result<()> {
Some(idx) => (&line[..idx], line[idx + 1 ..].trim()),
};
let dest: Vec<String> = dest.split(',').map(|name| name.trim().to_string()).collect();
let msg: String = msg.trim().to_string();
let msg: String = msg.to_string();
broker.send(Event::Message { // 4
from: name.clone(),

View file

@ -21,10 +21,7 @@ The order of events "Bob sends message to Alice" and "Alice joins" is determined
# };
# use futures::channel::mpsc;
# use futures::SinkExt;
# use std::{
# collections::hash_map::{Entry, HashMap},
# sync::Arc,
# };
# use std::sync::Arc;
#
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
# type Sender<T> = mpsc::UnboundedSender<T>;
@ -52,6 +49,8 @@ The order of events "Bob sends message to Alice" and "Alice joins" is determined
# })
# }
#
use std::collections::hash_map::{Entry, HashMap};
#[derive(Debug)]
enum Event { // 1
NewPeer {