diff --git a/examples/chat.rs b/examples/chat.rs index fdf7246b06..9d3762ca2d 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -10,14 +10,12 @@ use std::collections::HashSet; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; -use futures::{sink::SinkExt, stream::StreamExt}; - -use tokio::sync::broadcast; - use axum::prelude::*; use axum::response::Html; use axum::ws::{ws, Message, WebSocket}; use axum::AddExtensionLayer; +use futures::{sink::SinkExt, stream::StreamExt}; +use tokio::sync::broadcast; // Our shared state struct AppState { diff --git a/examples/error_handling_and_dependency_injection.rs b/examples/error_handling_and_dependency_injection.rs index dbc3fa28b0..b667a7c5ac 100644 --- a/examples/error_handling_and_dependency_injection.rs +++ b/examples/error_handling_and_dependency_injection.rs @@ -9,6 +9,8 @@ #![allow(dead_code)] +use std::{net::SocketAddr, sync::Arc}; + use axum::{ async_trait, extract::{Extension, Json, UrlParams}, @@ -19,7 +21,6 @@ use axum::{ use http::StatusCode; use serde::{Deserialize, Serialize}; use serde_json::json; -use std::{net::SocketAddr, sync::Arc}; use uuid::Uuid; #[tokio::main] diff --git a/examples/form.rs b/examples/form.rs index ec04869b20..3d867e1aeb 100644 --- a/examples/form.rs +++ b/examples/form.rs @@ -4,9 +4,10 @@ //! cargo run --example form //! ``` +use std::net::SocketAddr; + use axum::prelude::*; use serde::Deserialize; -use std::net::SocketAddr; #[tokio::main] async fn main() { diff --git a/examples/hello_world.rs b/examples/hello_world.rs index d49f069206..131ad9612c 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -4,9 +4,10 @@ //! cargo run --example hello_world //! ``` -use axum::prelude::*; use std::net::SocketAddr; +use axum::prelude::*; + #[tokio::main] async fn main() { tracing_subscriber::fmt::init(); diff --git a/examples/key_value_store.rs b/examples/key_value_store.rs index 506c44be51..3f5bb4d0ba 100644 --- a/examples/key_value_store.rs +++ b/examples/key_value_store.rs @@ -6,6 +6,15 @@ //! cargo run --example key_value_store //! ``` +use std::{ + borrow::Cow, + collections::HashMap, + convert::Infallible, + net::SocketAddr, + sync::{Arc, RwLock}, + time::Duration, +}; + use axum::{ async_trait, extract::{extractor_middleware, ContentLengthLimit, Extension, RequestParts, UrlParams}, @@ -16,14 +25,6 @@ use axum::{ }; use bytes::Bytes; use http::StatusCode; -use std::{ - borrow::Cow, - collections::HashMap, - convert::Infallible, - net::SocketAddr, - sync::{Arc, RwLock}, - time::Duration, -}; use tower::{BoxError, ServiceBuilder}; use tower_http::{ add_extension::AddExtensionLayer, compression::CompressionLayer, trace::TraceLayer, diff --git a/examples/multipart_form.rs b/examples/multipart_form.rs index d8f70ba7c5..ce6f2db24c 100644 --- a/examples/multipart_form.rs +++ b/examples/multipart_form.rs @@ -4,11 +4,12 @@ //! cargo run --example multipart_form --features=multipart //! ``` +use std::net::SocketAddr; + use axum::{ extract::{ContentLengthLimit, Multipart}, prelude::*, }; -use std::net::SocketAddr; #[tokio::main] async fn main() { diff --git a/examples/sessions.rs b/examples/sessions.rs index f865f6d043..2dfad33231 100644 --- a/examples/sessions.rs +++ b/examples/sessions.rs @@ -4,6 +4,8 @@ //! cargo run --example sessions //! ``` +use std::net::SocketAddr; + use async_session::{MemoryStore, Session, SessionStore as _}; use axum::{ async_trait, @@ -15,7 +17,6 @@ use axum::{ use http::header::{HeaderMap, HeaderValue}; use http::StatusCode; use serde::{Deserialize, Serialize}; -use std::net::SocketAddr; use uuid::Uuid; #[tokio::main] diff --git a/examples/sse.rs b/examples/sse.rs index c30951dbdc..e4ff53b126 100644 --- a/examples/sse.rs +++ b/examples/sse.rs @@ -4,10 +4,11 @@ //! cargo run --example sse --features=headers //! ``` +use std::{convert::Infallible, net::SocketAddr, time::Duration}; + use axum::{extract::TypedHeader, prelude::*, routing::nest, service::ServiceExt, sse::Event}; use futures::stream::{self, Stream}; use http::StatusCode; -use std::{convert::Infallible, net::SocketAddr, time::Duration}; use tokio_stream::StreamExt as _; use tower_http::{services::ServeDir, trace::TraceLayer}; diff --git a/examples/static_file_server.rs b/examples/static_file_server.rs index cc435cf4a9..de9c3a7704 100644 --- a/examples/static_file_server.rs +++ b/examples/static_file_server.rs @@ -4,9 +4,10 @@ //! cargo run --example static_file_server //! ``` +use std::net::SocketAddr; + use axum::{prelude::*, routing::nest, service::ServiceExt}; use http::StatusCode; -use std::net::SocketAddr; use tower_http::{services::ServeDir, trace::TraceLayer}; #[tokio::main] diff --git a/examples/templates.rs b/examples/templates.rs index f7e47be5d5..b69f2e11e7 100644 --- a/examples/templates.rs +++ b/examples/templates.rs @@ -4,10 +4,11 @@ //! cargo run --example templates //! ``` +use std::net::SocketAddr; + use askama::Template; use axum::{prelude::*, response::IntoResponse}; use http::{Response, StatusCode}; -use std::net::SocketAddr; #[tokio::main] async fn main() { diff --git a/examples/tls_rustls.rs b/examples/tls_rustls.rs index fa36ccee7e..18f9a37812 100644 --- a/examples/tls_rustls.rs +++ b/examples/tls_rustls.rs @@ -4,9 +4,10 @@ //! cargo run --example tls_rustls //! ``` +use std::{fs::File, io::BufReader, sync::Arc}; + use axum::prelude::*; use hyper::server::conn::Http; -use std::{fs::File, io::BufReader, sync::Arc}; use tokio::net::TcpListener; use tokio_rustls::{ rustls::{ diff --git a/examples/todos.rs b/examples/todos.rs index 5ad1f847b8..7e7d4c6a2e 100644 --- a/examples/todos.rs +++ b/examples/todos.rs @@ -13,6 +13,14 @@ //! cargo run --example todos //! ``` +use std::{ + collections::HashMap, + convert::Infallible, + net::SocketAddr, + sync::{Arc, RwLock}, + time::Duration, +}; + use axum::{ extract::{Extension, Json, Query, UrlParams}, prelude::*, @@ -21,13 +29,6 @@ use axum::{ }; use http::StatusCode; use serde::{Deserialize, Serialize}; -use std::{ - collections::HashMap, - convert::Infallible, - net::SocketAddr, - sync::{Arc, RwLock}, - time::Duration, -}; use tower::{BoxError, ServiceBuilder}; use tower_http::{add_extension::AddExtensionLayer, trace::TraceLayer}; use uuid::Uuid; diff --git a/examples/tokio_postgres.rs b/examples/tokio_postgres.rs index 429b8c8347..e1c42a5148 100644 --- a/examples/tokio_postgres.rs +++ b/examples/tokio_postgres.rs @@ -4,11 +4,12 @@ //! cargo run --example tokio_postgres //! ``` +use std::net::SocketAddr; + use axum::{extract::Extension, prelude::*, AddExtensionLayer}; use bb8::Pool; use bb8_postgres::PostgresConnectionManager; use http::StatusCode; -use std::net::SocketAddr; use tokio_postgres::NoTls; #[tokio::main] diff --git a/examples/unix_domain_socket.rs b/examples/unix_domain_socket.rs index d8fcd8df9f..78a11c4c4f 100644 --- a/examples/unix_domain_socket.rs +++ b/examples/unix_domain_socket.rs @@ -4,6 +4,14 @@ //! cargo run --example unix_domain_socket //! ``` +use std::{ + io, + path::PathBuf, + pin::Pin, + sync::Arc, + task::{Context, Poll}, +}; + use axum::{ extract::connect_info::{self, ConnectInfo}, prelude::*, @@ -14,13 +22,6 @@ use hyper::{ client::connect::{Connected, Connection}, server::accept::Accept, }; -use std::{ - io, - path::PathBuf, - pin::Pin, - sync::Arc, - task::{Context, Poll}, -}; use tokio::net::{unix::UCred, UnixListener}; use tokio::{ io::{AsyncRead, AsyncWrite}, diff --git a/examples/versioning.rs b/examples/versioning.rs index 406bec5534..98be50fe19 100644 --- a/examples/versioning.rs +++ b/examples/versioning.rs @@ -4,6 +4,8 @@ //! cargo run --example versioning //! ``` +use std::net::SocketAddr; + use axum::response::IntoResponse; use axum::{ async_trait, @@ -12,7 +14,6 @@ use axum::{ }; use http::Response; use http::StatusCode; -use std::net::SocketAddr; #[tokio::main] async fn main() { diff --git a/examples/websocket.rs b/examples/websocket.rs index 26cf3e2564..a8174843ee 100644 --- a/examples/websocket.rs +++ b/examples/websocket.rs @@ -6,6 +6,8 @@ //! RUST_LOG=tower_http=debug,key_value_store=trace cargo run --features=ws,headers --example websocket //! ``` +use std::net::SocketAddr; + use axum::{ extract::TypedHeader, prelude::*, @@ -14,7 +16,6 @@ use axum::{ ws::{ws, Message, WebSocket}, }; use http::StatusCode; -use std::net::SocketAddr; use tower_http::{ services::ServeDir, trace::{DefaultMakeSpan, TraceLayer}, diff --git a/src/body.rs b/src/body.rs index 767f2daf95..96b43ae7e0 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,8 +1,9 @@ //! HTTP body utilities. +use std::{error::Error as StdError, fmt}; + use bytes::Bytes; use http_body::Body as _; -use std::{error::Error as StdError, fmt}; use tower::BoxError; pub use hyper::body::Body; diff --git a/src/buffer.rs b/src/buffer.rs index c7134adcfc..537e1d07d9 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1,11 +1,12 @@ -use futures_util::ready; -use pin_project::pin_project; use std::{ future::Future, pin::Pin, sync::Arc, task::{Context, Poll}, }; + +use futures_util::ready; +use pin_project::pin_project; use tokio::sync::{mpsc, oneshot, OwnedSemaphorePermit, Semaphore}; use tokio_util::sync::PollSemaphore; use tower::{Service, ServiceExt}; diff --git a/src/extract/connect_info.rs b/src/extract/connect_info.rs index cb92e09565..581ed3f35b 100644 --- a/src/extract/connect_info.rs +++ b/src/extract/connect_info.rs @@ -4,9 +4,6 @@ //! //! [`RoutingDsl::into_make_service_with_connect_info`]: crate::routing::RoutingDsl::into_make_service_with_connect_info -use super::{Extension, FromRequest, RequestParts}; -use async_trait::async_trait; -use hyper::server::conn::AddrStream; use std::{ convert::Infallible, fmt, @@ -14,9 +11,14 @@ use std::{ net::SocketAddr, task::{Context, Poll}, }; + +use async_trait::async_trait; +use hyper::server::conn::AddrStream; use tower::Service; use tower_http::add_extension::AddExtension; +use super::{Extension, FromRequest, RequestParts}; + /// A [`MakeService`] created from a router. /// /// See [`RoutingDsl::into_make_service_with_connect_info`] for more details. diff --git a/src/extract/extractor_middleware.rs b/src/extract/extractor_middleware.rs index a8fa630146..2e89fc0849 100644 --- a/src/extract/extractor_middleware.rs +++ b/src/extract/extractor_middleware.rs @@ -2,12 +2,6 @@ //! //! See [`extractor_middleware`] for more details. -use super::{FromRequest, RequestParts}; -use crate::{body::BoxBody, response::IntoResponse}; -use bytes::Bytes; -use futures_util::{future::BoxFuture, ready}; -use http::{Request, Response}; -use pin_project::pin_project; use std::{ fmt, future::Future, @@ -15,8 +9,16 @@ use std::{ pin::Pin, task::{Context, Poll}, }; + +use bytes::Bytes; +use futures_util::{future::BoxFuture, ready}; +use http::{Request, Response}; +use pin_project::pin_project; use tower::{BoxError, Layer, Service}; +use super::{FromRequest, RequestParts}; +use crate::{body::BoxBody, response::IntoResponse}; + /// Convert an extractor into a middleware. /// /// If the extractor succeeds the value will be discarded and the inner service diff --git a/src/extract/mod.rs b/src/extract/mod.rs index 0f286f2c65..2cf79635d9 100644 --- a/src/extract/mod.rs +++ b/src/extract/mod.rs @@ -244,13 +244,6 @@ //! //! [`body::Body`]: crate::body::Body -use crate::{response::IntoResponse, util::ByteStr}; -use async_trait::async_trait; -use bytes::{Buf, Bytes}; -use futures_util::stream::Stream; -use http::{header, Extensions, HeaderMap, Method, Request, Response, Uri, Version}; -use rejection::*; -use serde::de::DeserializeOwned; use std::{ collections::HashMap, convert::Infallible, @@ -260,6 +253,15 @@ use std::{ task::{Context, Poll}, }; +use async_trait::async_trait; +use bytes::{Buf, Bytes}; +use futures_util::stream::Stream; +use http::{header, Extensions, HeaderMap, Method, Request, Response, Uri, Version}; +use rejection::*; +use serde::de::DeserializeOwned; + +use crate::{response::IntoResponse, util::ByteStr}; + pub mod connect_info; pub mod extractor_middleware; pub mod rejection; diff --git a/src/extract/multipart.rs b/src/extract/multipart.rs index acae08b825..58cf61e5c9 100644 --- a/src/extract/multipart.rs +++ b/src/extract/multipart.rs @@ -2,19 +2,21 @@ //! //! See [`Multipart`] for more details. -use super::{rejection::*, BodyStream, FromRequest, RequestParts}; -use async_trait::async_trait; -use bytes::Bytes; -use futures_util::stream::Stream; -use http::header::{HeaderMap, CONTENT_TYPE}; -use mime::Mime; use std::{ fmt, pin::Pin, task::{Context, Poll}, }; + +use async_trait::async_trait; +use bytes::Bytes; +use futures_util::stream::Stream; +use http::header::{HeaderMap, CONTENT_TYPE}; +use mime::Mime; use tower::BoxError; +use super::{rejection::*, BodyStream, FromRequest, RequestParts}; + /// Extractor that parses `multipart/form-data` requests commonly used with file uploads. /// /// # Example diff --git a/src/extract/rejection.rs b/src/extract/rejection.rs index bfa72a9536..949001242f 100644 --- a/src/extract/rejection.rs +++ b/src/extract/rejection.rs @@ -1,8 +1,9 @@ //! Rejection response types. +use tower::BoxError; + use super::IntoResponse; use crate::body::Body; -use tower::BoxError; define_rejection! { #[status = INTERNAL_SERVER_ERROR] diff --git a/src/handler/future.rs b/src/handler/future.rs index f593fde140..ce5c629223 100644 --- a/src/handler/future.rs +++ b/src/handler/future.rs @@ -1,9 +1,11 @@ //! Handler future types. -use crate::body::BoxBody; -use http::Response; use std::convert::Infallible; +use http::Response; + +use crate::body::BoxBody; + opaque_future! { /// The response future for [`IntoService`](super::IntoService). pub type IntoServiceFuture = diff --git a/src/handler/mod.rs b/src/handler/mod.rs index aaa9792ac5..c21f75ceac 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -1,15 +1,5 @@ //! Async functions that can be used to handle requests. -use crate::{ - body::{box_body, BoxBody}, - extract::FromRequest, - response::IntoResponse, - routing::{EmptyRouter, MethodFilter, RouteFuture}, - service::HandleError, -}; -use async_trait::async_trait; -use bytes::Bytes; -use http::{Request, Response}; use std::{ convert::Infallible, fmt, @@ -17,8 +7,20 @@ use std::{ marker::PhantomData, task::{Context, Poll}, }; + +use async_trait::async_trait; +use bytes::Bytes; +use http::{Request, Response}; use tower::{BoxError, Layer, Service, ServiceExt}; +use crate::{ + body::{box_body, BoxBody}, + extract::FromRequest, + response::IntoResponse, + routing::{EmptyRouter, MethodFilter, RouteFuture}, + service::HandleError, +}; + pub mod future; /// Route requests to the given handler regardless of the HTTP method of the diff --git a/src/lib.rs b/src/lib.rs index 318f6c37a9..8b6adcc022 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -718,11 +718,12 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(test, allow(clippy::float_cmp))] -use self::body::Body; use http::Request; use routing::{EmptyRouter, Route}; use tower::Service; +use self::body::Body; + #[macro_use] pub(crate) mod macros; diff --git a/src/response.rs b/src/response.rs index 80d2d7a2c3..e8854e4bed 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,12 +1,14 @@ //! Types and traits for generating responses. -use crate::Body; +use std::{borrow::Cow, convert::Infallible}; + use bytes::Bytes; use http::{header, HeaderMap, HeaderValue, Response, StatusCode}; use serde::Serialize; -use std::{borrow::Cow, convert::Infallible}; use tower::util::Either; +use crate::Body; + /// Trait for generating responses. /// /// Types that implement `IntoResponse` can be returned from handlers. diff --git a/src/routing.rs b/src/routing.rs index 21f79d41b2..6bb2f8fb52 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -1,18 +1,5 @@ //! Routing between [`Service`]s. -use crate::{ - body::{box_body, BoxBody}, - buffer::MpscBuffer, - extract::connect_info::{Connected, IntoMakeServiceWithConnectInfo}, - response::IntoResponse, - util::ByteStr, -}; -use async_trait::async_trait; -use bytes::Bytes; -use futures_util::future; -use http::{Method, Request, Response, StatusCode, Uri}; -use pin_project::pin_project; -use regex::Regex; use std::{ borrow::Cow, convert::Infallible, @@ -23,12 +10,27 @@ use std::{ sync::Arc, task::{Context, Poll}, }; + +use async_trait::async_trait; +use bytes::Bytes; +use futures_util::future; +use http::{Method, Request, Response, StatusCode, Uri}; +use pin_project::pin_project; +use regex::Regex; use tower::{ util::{BoxService, Oneshot, ServiceExt}, BoxError, Layer, Service, ServiceBuilder, }; use tower_http::map_response_body::MapResponseBodyLayer; +use crate::{ + body::{box_body, BoxBody}, + buffer::MpscBuffer, + extract::connect_info::{Connected, IntoMakeServiceWithConnectInfo}, + response::IntoResponse, + util::ByteStr, +}; + /// A filter that matches one or more HTTP methods. #[derive(Debug, Copy, Clone)] pub enum MethodFilter { diff --git a/src/service/future.rs b/src/service/future.rs index 7e6cd421b3..2740351081 100644 --- a/src/service/future.rs +++ b/src/service/future.rs @@ -1,20 +1,22 @@ //! [`Service`](tower::Service) future types. -use crate::{ - body::{box_body, BoxBody}, - response::IntoResponse, -}; -use bytes::Bytes; -use futures_util::ready; -use http::Response; -use pin_project::pin_project; use std::{ future::Future, pin::Pin, task::{Context, Poll}, }; + +use bytes::Bytes; +use futures_util::ready; +use http::Response; +use pin_project::pin_project; use tower::BoxError; +use crate::{ + body::{box_body, BoxBody}, + response::IntoResponse, +}; + /// Response future for [`HandleError`](super::HandleError). #[pin_project] #[derive(Debug)] diff --git a/src/service/mod.rs b/src/service/mod.rs index 7e90468dcf..2fb64bfd2e 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -86,15 +86,6 @@ //! [`Redirect`]: tower_http::services::Redirect //! [load shed]: tower::load_shed -use crate::{ - body::{box_body, BoxBody}, - response::IntoResponse, - routing::{EmptyRouter, MethodFilter, RouteFuture}, -}; -use bytes::Bytes; -use futures_util::ready; -use http::{Request, Response}; -use pin_project::pin_project; use std::{ convert::Infallible, fmt, @@ -102,8 +93,19 @@ use std::{ marker::PhantomData, task::{Context, Poll}, }; + +use bytes::Bytes; +use futures_util::ready; +use http::{Request, Response}; +use pin_project::pin_project; use tower::{util::Oneshot, BoxError, Service, ServiceExt as _}; +use crate::{ + body::{box_body, BoxBody}, + response::IntoResponse, + routing::{EmptyRouter, MethodFilter, RouteFuture}, +}; + pub mod future; /// Route requests to the given service regardless of the HTTP method. diff --git a/src/sse.rs b/src/sse.rs index b7ee46cee6..87ca66980c 100644 --- a/src/sse.rs +++ b/src/sse.rs @@ -69,20 +69,6 @@ //! # }; //! ``` -use crate::{ - body::{box_body, BoxBody, BoxStdError}, - extract::{FromRequest, RequestParts}, - response::IntoResponse, -}; -use async_trait::async_trait; -use futures_util::{ - future::{TryFuture, TryFutureExt}, - stream::{Stream, StreamExt, TryStream, TryStreamExt}, -}; -use http::{Request, Response}; -use hyper::Body; -use pin_project::pin_project; -use serde::Serialize; use std::{ borrow::Cow, convert::Infallible, @@ -93,9 +79,25 @@ use std::{ task::{Context, Poll}, time::Duration, }; + +use async_trait::async_trait; +use futures_util::{ + future::{TryFuture, TryFutureExt}, + stream::{Stream, StreamExt, TryStream, TryStreamExt}, +}; +use http::{Request, Response}; +use hyper::Body; +use pin_project::pin_project; +use serde::Serialize; use tokio::time::Sleep; use tower::{BoxError, Service}; +use crate::{ + body::{box_body, BoxBody, BoxStdError}, + extract::{FromRequest, RequestParts}, + response::IntoResponse, +}; + /// Create a new [`Sse`] service that will call the closure to produce a stream /// of [`Event`]s. /// diff --git a/src/tests.rs b/src/tests.rs index 6d8e59734b..cd5ac858c0 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,22 +1,24 @@ -use crate::{ - extract::RequestParts, handler::on, prelude::*, response::IntoResponse, routing::nest, - routing::MethodFilter, service, +use std::{ + convert::Infallible, + net::{SocketAddr, TcpListener}, + task::{Context, Poll}, + time::Duration, }; + use bytes::Bytes; use futures_util::future::Ready; use http::{header::AUTHORIZATION, Request, Response, StatusCode, Uri}; use hyper::{Body, Server}; use serde::Deserialize; use serde_json::json; -use std::{ - convert::Infallible, - net::{SocketAddr, TcpListener}, - task::{Context, Poll}, - time::Duration, -}; use tower::{make::Shared, service_fn, BoxError, Service, ServiceBuilder}; use tower_http::{compression::CompressionLayer, trace::TraceLayer}; +use crate::{ + extract::RequestParts, handler::on, prelude::*, response::IntoResponse, routing::nest, + routing::MethodFilter, service, +}; + mod nest; #[tokio::test] diff --git a/src/ws/future.rs b/src/ws/future.rs index 0791245507..395da4e0fa 100644 --- a/src/ws/future.rs +++ b/src/ws/future.rs @@ -1,9 +1,11 @@ //! Future types. -use crate::body::BoxBody; -use http::Response; use std::convert::Infallible; +use http::Response; + +use crate::body::BoxBody; + opaque_future! { /// Response future for [`WebSocketUpgrade`](super::WebSocketUpgrade). pub type ResponseFuture = futures_util::future::BoxFuture<'static, Result, Infallible>>; diff --git a/src/ws/mod.rs b/src/ws/mod.rs index 8d5729cb4a..16e44ed417 100644 --- a/src/ws/mod.rs +++ b/src/ws/mod.rs @@ -55,9 +55,12 @@ //! # }; //! ``` -use crate::body::{box_body, BoxBody}; -use crate::extract::{FromRequest, RequestParts}; -use crate::response::IntoResponse; +use std::pin::Pin; +use std::{ + borrow::Cow, convert::Infallible, fmt, future::Future, marker::PhantomData, task::Context, + task::Poll, +}; + use async_trait::async_trait; use bytes::Bytes; use future::ResponseFuture; @@ -72,17 +75,16 @@ use http::{ use http_body::Full; use hyper::upgrade::{OnUpgrade, Upgraded}; use sha1::{Digest, Sha1}; -use std::pin::Pin; -use std::{ - borrow::Cow, convert::Infallible, fmt, future::Future, marker::PhantomData, task::Context, - task::Poll, -}; use tokio_tungstenite::{ tungstenite::protocol::{self, WebSocketConfig}, WebSocketStream, }; use tower::{BoxError, Service}; +use crate::body::{box_body, BoxBody}; +use crate::extract::{FromRequest, RequestParts}; +use crate::response::IntoResponse; + pub mod future; /// Create a new [`WebSocketUpgrade`] service that will call the closure with