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)]
|
||||
|
||||
use {
|
||||
futures::{
|
||||
executor::block_on,
|
||||
join,
|
||||
},
|
||||
std::thread,
|
||||
};
|
||||
use futures::{executor::block_on, join};
|
||||
use std::thread;
|
||||
|
||||
fn download(_url: &str) {
|
||||
// ...
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
#![cfg(test)]
|
||||
|
||||
// ANCHOR: imports
|
||||
use {
|
||||
futures::{
|
||||
future::{BoxFuture, FutureExt},
|
||||
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 futures::{
|
||||
future::{BoxFuture, FutureExt},
|
||||
task::{waker_ref, ArcWake},
|
||||
};
|
||||
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: executor_decl
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#![cfg(test)]
|
||||
|
||||
mod stream_trait {
|
||||
use {
|
||||
futures::stream::{Stream as RealStream},
|
||||
std::{
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
},
|
||||
use futures::stream::Stream as RealStream;
|
||||
use std::{
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
// ANCHOR: stream_trait
|
||||
|
@ -34,11 +32,9 @@ impl<I> Stream for dyn RealStream<Item = I> {
|
|||
}
|
||||
|
||||
mod channels {
|
||||
use {
|
||||
futures::{
|
||||
channel::mpsc,
|
||||
prelude::*,
|
||||
},
|
||||
use futures::{
|
||||
channel::mpsc,
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
// ANCHOR: channels
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
#![cfg(test)]
|
||||
|
||||
use {
|
||||
futures::{
|
||||
executor::block_on,
|
||||
stream::{self, Stream},
|
||||
},
|
||||
std::{
|
||||
io,
|
||||
pin::Pin,
|
||||
},
|
||||
use futures::{
|
||||
executor::block_on,
|
||||
stream::{self, Stream},
|
||||
};
|
||||
use std::{
|
||||
io,
|
||||
pin::Pin,
|
||||
};
|
||||
|
||||
// ANCHOR: nexts
|
||||
|
|
|
@ -21,7 +21,6 @@ async fn main() {
|
|||
// ANCHOR_END: main_func
|
||||
|
||||
use async_std::io::{Read, Write};
|
||||
use std::marker::Unpin;
|
||||
|
||||
async fn handle_connection(mut stream: impl Read + Write + Unpin) {
|
||||
let mut buffer = [0; 1024];
|
||||
|
@ -90,7 +89,6 @@ mod tests {
|
|||
// ANCHOR_END: mock_write
|
||||
|
||||
// ANCHOR: unpin
|
||||
use std::marker::Unpin;
|
||||
impl Unpin for MockTcpStream {}
|
||||
// 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`.
|
||||
Changing the type signature to reflect this allows us to pass a mock for testing.
|
||||
```rust,ignore
|
||||
use std::marker::Unpin;
|
||||
use async_std::io::{Read, Write};
|
||||
|
||||
async fn handle_connection(mut stream: impl Read + Write + Unpin) {
|
||||
|
|
Loading…
Reference in New Issue