Unify import style

This commit is contained in:
Taiki Endo 2022-07-30 18:16:29 +09:00
parent 1fb57ec5dd
commit a7974c8de8
7 changed files with 30 additions and 44 deletions

2
.rustfmt.toml Normal file
View File

@ -0,0 +1,2 @@
# https://github.com/rust-lang/async-book/pull/59#issuecomment-556240879
disable_all_formatting = true

View File

@ -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) {
// ...

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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) {