forked from mirror/async-std
Merge pull request #112 from async-rs/fix-101
Import HashMap visibly in the tutorial
This commit is contained in:
commit
d501bf6849
3 changed files with 6 additions and 8 deletions
|
@ -6,9 +6,8 @@ In `async-std`, the [`tasks`][tasks] module is responsible for this. The simples
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# use async_std::{fs::File, io::Read, task};
|
use async_std::{io, task, fs::File, io::Read};
|
||||||
# use std::io;
|
|
||||||
#
|
|
||||||
async fn read_file(path: &str) -> Result<String, io::Error> {
|
async fn read_file(path: &str) -> Result<String, io::Error> {
|
||||||
let mut file = File::open(path).await?;
|
let mut file = File::open(path).await?;
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
|
|
|
@ -74,7 +74,7 @@ async fn client(mut broker: Sender<Event>, stream: TcpStream) -> Result<()> {
|
||||||
Some(idx) => (&line[..idx], line[idx + 1 ..].trim()),
|
Some(idx) => (&line[..idx], line[idx + 1 ..].trim()),
|
||||||
};
|
};
|
||||||
let dest: Vec<String> = dest.split(',').map(|name| name.trim().to_string()).collect();
|
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
|
broker.send(Event::Message { // 4
|
||||||
from: name.clone(),
|
from: name.clone(),
|
||||||
|
|
|
@ -21,10 +21,7 @@ The order of events "Bob sends message to Alice" and "Alice joins" is determined
|
||||||
# };
|
# };
|
||||||
# use futures::channel::mpsc;
|
# use futures::channel::mpsc;
|
||||||
# use futures::SinkExt;
|
# use futures::SinkExt;
|
||||||
# use std::{
|
# use std::sync::Arc;
|
||||||
# collections::hash_map::{Entry, HashMap},
|
|
||||||
# sync::Arc,
|
|
||||||
# };
|
|
||||||
#
|
#
|
||||||
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
# type Sender<T> = mpsc::UnboundedSender<T>;
|
# 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)]
|
#[derive(Debug)]
|
||||||
enum Event { // 1
|
enum Event { // 1
|
||||||
NewPeer {
|
NewPeer {
|
||||||
|
|
Loading…
Reference in a new issue