mirror of https://github.com/rust-lang/async-book
Unify import style
This commit is contained in:
parent
1fb57ec5dd
commit
a7974c8de8
|
@ -0,0 +1,2 @@
|
||||||
|
# https://github.com/rust-lang/async-book/pull/59#issuecomment-556240879
|
||||||
|
disable_all_formatting = true
|
|
@ -1,12 +1,7 @@
|
||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
|
|
||||||
use {
|
use futures::{executor::block_on, join};
|
||||||
futures::{
|
use std::thread;
|
||||||
executor::block_on,
|
|
||||||
join,
|
|
||||||
},
|
|
||||||
std::thread,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn download(_url: &str) {
|
fn download(_url: &str) {
|
||||||
// ...
|
// ...
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
|
|
||||||
// ANCHOR: imports
|
// ANCHOR: imports
|
||||||
use {
|
use futures::{
|
||||||
futures::{
|
future::{BoxFuture, FutureExt},
|
||||||
future::{BoxFuture, FutureExt},
|
task::{waker_ref, ArcWake},
|
||||||
task::{waker_ref, ArcWake},
|
|
||||||
},
|
|
||||||
std::{
|
|
||||||
future::Future,
|
|
||||||
sync::mpsc::{sync_channel, Receiver, SyncSender},
|
|
||||||
sync::{Arc, Mutex},
|
|
||||||
task::Context,
|
|
||||||
time::Duration,
|
|
||||||
},
|
|
||||||
// The timer we wrote in the previous section:
|
|
||||||
timer_future::TimerFuture,
|
|
||||||
};
|
};
|
||||||
|
use std::{
|
||||||
|
future::Future,
|
||||||
|
sync::mpsc::{sync_channel, Receiver, SyncSender},
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
task::Context,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
// The timer we wrote in the previous section:
|
||||||
|
use timer_future::TimerFuture;
|
||||||
// ANCHOR_END: imports
|
// ANCHOR_END: imports
|
||||||
|
|
||||||
// ANCHOR: executor_decl
|
// ANCHOR: executor_decl
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
|
|
||||||
mod stream_trait {
|
mod stream_trait {
|
||||||
use {
|
use futures::stream::Stream as RealStream;
|
||||||
futures::stream::{Stream as RealStream},
|
use std::{
|
||||||
std::{
|
pin::Pin,
|
||||||
pin::Pin,
|
task::{Context, Poll},
|
||||||
task::{Context, Poll},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ANCHOR: stream_trait
|
// ANCHOR: stream_trait
|
||||||
|
@ -34,11 +32,9 @@ impl<I> Stream for dyn RealStream<Item = I> {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod channels {
|
mod channels {
|
||||||
use {
|
use futures::{
|
||||||
futures::{
|
channel::mpsc,
|
||||||
channel::mpsc,
|
prelude::*,
|
||||||
prelude::*,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ANCHOR: channels
|
// ANCHOR: channels
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
|
|
||||||
use {
|
use futures::{
|
||||||
futures::{
|
executor::block_on,
|
||||||
executor::block_on,
|
stream::{self, Stream},
|
||||||
stream::{self, Stream},
|
};
|
||||||
},
|
use std::{
|
||||||
std::{
|
io,
|
||||||
io,
|
pin::Pin,
|
||||||
pin::Pin,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ANCHOR: nexts
|
// ANCHOR: nexts
|
||||||
|
|
|
@ -21,7 +21,6 @@ async fn main() {
|
||||||
// ANCHOR_END: main_func
|
// ANCHOR_END: main_func
|
||||||
|
|
||||||
use async_std::io::{Read, Write};
|
use async_std::io::{Read, Write};
|
||||||
use std::marker::Unpin;
|
|
||||||
|
|
||||||
async fn handle_connection(mut stream: impl Read + Write + Unpin) {
|
async fn handle_connection(mut stream: impl Read + Write + Unpin) {
|
||||||
let mut buffer = [0; 1024];
|
let mut buffer = [0; 1024];
|
||||||
|
@ -90,7 +89,6 @@ mod tests {
|
||||||
// ANCHOR_END: mock_write
|
// ANCHOR_END: mock_write
|
||||||
|
|
||||||
// ANCHOR: unpin
|
// ANCHOR: unpin
|
||||||
use std::marker::Unpin;
|
|
||||||
impl Unpin for MockTcpStream {}
|
impl Unpin for MockTcpStream {}
|
||||||
// ANCHOR_END: unpin
|
// ANCHOR_END: unpin
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ First, we'll change the signature of `handle_connection` to make it easier to te
|
||||||
it requires any struct that implements `async_std::io::Read`, `async_std::io::Write`, and `marker::Unpin`.
|
it requires any struct that implements `async_std::io::Read`, `async_std::io::Write`, and `marker::Unpin`.
|
||||||
Changing the type signature to reflect this allows us to pass a mock for testing.
|
Changing the type signature to reflect this allows us to pass a mock for testing.
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
use std::marker::Unpin;
|
|
||||||
use async_std::io::{Read, Write};
|
use async_std::io::{Read, Write};
|
||||||
|
|
||||||
async fn handle_connection(mut stream: impl Read + Write + Unpin) {
|
async fn handle_connection(mut stream: impl Read + Write + Unpin) {
|
||||||
|
|
Loading…
Reference in New Issue