Remove axum::prelude (#195)

This commit is contained in:
Florian Thelliez
2021-08-18 00:04:15 +02:00
committed by GitHub
parent f083c3e97e
commit d9a06ef14b
43 changed files with 529 additions and 171 deletions
+1 -1
View File
@@ -130,8 +130,8 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::prelude::*;
use crate::Server;
use crate::{handler::get, route, routing::RoutingDsl};
use std::net::{SocketAddr, TcpListener};
#[tokio::test]
+7 -2
View File
@@ -9,9 +9,14 @@ use std::ops::Deref;
/// # Example
///
/// ```rust,no_run
/// use axum::prelude::*;
/// use axum::{
/// extract::ContentLengthLimit,
/// handler::post,
/// route,
/// routing::RoutingDsl
/// };
///
/// async fn handler(body: extract::ContentLengthLimit<String, 1024>) {
/// async fn handler(body: ContentLengthLimit<String, 1024>) {
/// // ...
/// }
///
+8 -2
View File
@@ -9,7 +9,13 @@ use std::ops::Deref;
/// # Example
///
/// ```rust,no_run
/// use axum::{AddExtensionLayer, prelude::*};
/// use axum::{
/// AddExtensionLayer,
/// extract::Extension,
/// handler::get,
/// route,
/// routing::RoutingDsl
/// };
/// use std::sync::Arc;
///
/// // Some shared state used throughout our application
@@ -17,7 +23,7 @@ use std::ops::Deref;
/// // ...
/// }
///
/// async fn handler(state: extract::Extension<Arc<State>>) {
/// async fn handler(state: Extension<Arc<State>>) {
/// // ...
/// }
///
+7 -2
View File
@@ -34,7 +34,12 @@ use tower::{BoxError, Layer, Service};
/// # Example
///
/// ```rust
/// use axum::{extract::{extractor_middleware, RequestParts}, prelude::*};
/// use axum::{
/// extract::{extractor_middleware, FromRequest, RequestParts},
/// handler::{get, post},
/// route,
/// routing::RoutingDsl
/// };
/// use http::StatusCode;
/// use async_trait::async_trait;
///
@@ -42,7 +47,7 @@ use tower::{BoxError, Layer, Service};
/// struct RequireAuth;
///
/// #[async_trait]
/// impl<B> extract::FromRequest<B> for RequireAuth
/// impl<B> FromRequest<B> for RequireAuth
/// where
/// B: Send,
/// {
+7 -2
View File
@@ -14,7 +14,12 @@ use tower::BoxError;
/// # Example
///
/// ```rust,no_run
/// use axum::prelude::*;
/// use axum::{
/// extract::Form,
/// handler::post,
/// route,
/// routing::RoutingDsl
/// };
/// use serde::Deserialize;
///
/// #[derive(Deserialize)]
@@ -23,7 +28,7 @@ use tower::BoxError;
/// password: String,
/// }
///
/// async fn accept_form(form: extract::Form<SignUp>) {
/// async fn accept_form(form: Form<SignUp>) {
/// let sign_up: SignUp = form.0;
///
/// // ...
+50 -12
View File
@@ -8,7 +8,12 @@
//! deserializes it as JSON into some target type:
//!
//! ```rust,no_run
//! use axum::prelude::*;
//! use axum::{
//! Json,
//! handler::{post, Handler},
//! route,
//! routing::RoutingDsl
//! };
//! use serde::Deserialize;
//!
//! #[derive(Deserialize)]
@@ -17,7 +22,7 @@
//! password: String,
//! }
//!
//! async fn create_user(payload: extract::Json<CreateUser>) {
//! async fn create_user(payload: Json<CreateUser>) {
//! let payload: CreateUser = payload.0;
//!
//! // ...
@@ -34,7 +39,13 @@
//! You can also define your own extractors by implementing [`FromRequest`]:
//!
//! ```rust,no_run
//! use axum::{async_trait, extract::{FromRequest, RequestParts}, prelude::*};
//! use axum::{
//! async_trait,
//! extract::{FromRequest, RequestParts},
//! handler::get,
//! route,
//! routing::RoutingDsl
//! };
//! use http::{StatusCode, header::{HeaderValue, USER_AGENT}};
//!
//! struct ExtractUserAgent(HeaderValue);
@@ -74,14 +85,19 @@
//! Handlers can also contain multiple extractors:
//!
//! ```rust,no_run
//! use axum::prelude::*;
//! use axum::{
//! extract::{Path, Query},
//! handler::get,
//! route,
//! routing::RoutingDsl
//! };
//! use std::collections::HashMap;
//!
//! async fn handler(
//! // Extract captured parameters from the URL
//! params: extract::Path<HashMap<String, String>>,
//! params: Path<HashMap<String, String>>,
//! // Parse query string into a `HashMap`
//! query_params: extract::Query<HashMap<String, String>>,
//! query_params: Query<HashMap<String, String>>,
//! // Buffer the request body into a `Bytes`
//! bytes: bytes::Bytes,
//! ) {
@@ -102,7 +118,12 @@
//! Wrapping extractors in `Option` will make them optional:
//!
//! ```rust,no_run
//! use axum::{extract::Json, prelude::*};
//! use axum::{
//! extract::Json,
//! handler::post,
//! route,
//! routing::RoutingDsl
//! };
//! use serde_json::Value;
//!
//! async fn create_user(payload: Option<Json<Value>>) {
@@ -123,7 +144,12 @@
//! the extraction failed:
//!
//! ```rust,no_run
//! use axum::{extract::{Json, rejection::JsonRejection}, prelude::*};
//! use axum::{
//! extract::{Json, rejection::JsonRejection},
//! handler::post,
//! route,
//! routing::RoutingDsl
//! };
//! use serde_json::Value;
//!
//! async fn create_user(payload: Result<Json<Value>, JsonRejection>) {
@@ -156,11 +182,16 @@
//!
//! # Reducing boilerplate
//!
//! If you're feeling adventorous you can even deconstruct the extractors
//! If you're feeling adventurous you can even deconstruct the extractors
//! directly on the function signature:
//!
//! ```rust,no_run
//! use axum::{extract::Json, prelude::*};
//! use axum::{
//! extract::Json,
//! handler::post,
//! route,
//! routing::RoutingDsl
//! };
//! use serde_json::Value;
//!
//! async fn create_user(Json(value): Json<Value>) {
@@ -187,7 +218,14 @@
//! pin::Pin,
//! };
//! use tower_http::map_request_body::MapRequestBodyLayer;
//! use axum::prelude::*;
//! use axum::{
//! extract::{self, BodyStream},
//! body::Body,
//! handler::get,
//! http::{header::HeaderMap, Request},
//! route,
//! routing::RoutingDsl
//! };
//!
//! struct MyBody<B>(B);
//!
@@ -208,7 +246,7 @@
//! fn poll_trailers(
//! mut self: Pin<&mut Self>,
//! cx: &mut Context<'_>,
//! ) -> Poll<Result<Option<headers::HeaderMap>, Self::Error>> {
//! ) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
//! Pin::new(&mut self.0).poll_trailers(cx)
//! }
//! }
+7 -2
View File
@@ -20,10 +20,15 @@ use tower::BoxError;
/// # Example
///
/// ```rust,no_run
/// use axum::prelude::*;
/// use axum::{
/// extract::Multipart,
/// handler::post,
/// route,
/// routing::RoutingDsl
/// };
/// use futures::stream::StreamExt;
///
/// async fn upload(mut multipart: extract::Multipart) {
/// async fn upload(mut multipart: Multipart) {
/// while let Some(mut field) = multipart.next_field().await.unwrap() {
/// let name = field.name().unwrap().to_string();
/// let data = field.bytes().await.unwrap();
+18 -3
View File
@@ -11,7 +11,12 @@ use std::ops::{Deref, DerefMut};
/// # Example
///
/// ```rust,no_run
/// use axum::{extract::Path, prelude::*};
/// use axum::{
/// extract::Path,
/// handler::get,
/// route,
/// routing::RoutingDsl
/// };
/// use uuid::Uuid;
///
/// async fn users_teams_show(
@@ -29,7 +34,12 @@ use std::ops::{Deref, DerefMut};
/// If the path contains only one parameter, then you can omit the tuple.
///
/// ```rust,no_run
/// use axum::{extract::Path, prelude::*};
/// use axum::{
/// extract::Path,
/// handler::get,
/// route,
/// routing::RoutingDsl,
/// };
/// use uuid::Uuid;
///
/// async fn user_info(Path(user_id): Path<Uuid>) {
@@ -46,7 +56,12 @@ use std::ops::{Deref, DerefMut};
/// Path segment labels will be matched with struct field names.
///
/// ```rust,no_run
/// use axum::{extract::Path, prelude::*};
/// use axum::{
/// extract::Path,
/// handler::get,
/// route,
/// routing::RoutingDsl
/// };
/// use serde::Deserialize;
/// use uuid::Uuid;
///
+7 -2
View File
@@ -10,7 +10,12 @@ use std::ops::Deref;
/// # Example
///
/// ```rust,no_run
/// use axum::prelude::*;
/// use axum::{
/// extract::Query,
/// handler::get,
/// route,
/// routing::RoutingDsl
/// };
/// use serde::Deserialize;
///
/// #[derive(Deserialize)]
@@ -21,7 +26,7 @@ use std::ops::Deref;
///
/// // This will parse query strings like `?page=2&per_page=30` into `Pagination`
/// // structs.
/// async fn list_things(pagination: extract::Query<Pagination>) {
/// async fn list_things(pagination: Query<Pagination>) {
/// let pagination: Pagination = pagination.0;
///
/// // ...
+7 -2
View File
@@ -7,10 +7,15 @@ use std::convert::Infallible;
/// # Example
///
/// ```rust,no_run
/// use axum::prelude::*;
/// use axum::{
/// extract::RawQuery,
/// handler::get,
/// route,
/// routing::RoutingDsl
/// };
/// use futures::StreamExt;
///
/// async fn handler(extract::RawQuery(query): extract::RawQuery) {
/// async fn handler(RawQuery(query): RawQuery) {
/// // ...
/// }
///
+22 -6
View File
@@ -90,7 +90,13 @@ where
/// # Example
///
/// ```
/// use axum::{prelude::*, routing::nest, extract::NestedUri, http::Uri};
/// use axum::{
/// handler::get,
/// route,
/// routing::{nest, RoutingDsl},
/// extract::NestedUri,
/// http::Uri
/// };
///
/// let api_routes = route(
/// "/users",
@@ -165,10 +171,15 @@ where
/// # Example
///
/// ```rust,no_run
/// use axum::prelude::*;
/// use axum::{
/// extract::BodyStream,
/// handler::get,
/// route,
/// routing::RoutingDsl
/// };
/// use futures::StreamExt;
///
/// async fn handler(mut stream: extract::BodyStream) {
/// async fn handler(mut stream: BodyStream) {
/// while let Some(chunk) = stream.next().await {
/// // ...
/// }
@@ -214,10 +225,15 @@ where
/// # Example
///
/// ```rust,no_run
/// use axum::prelude::*;
/// use axum::{
/// extract::Body,
/// handler::get,
/// route,
/// routing::RoutingDsl,
/// };
/// use futures::StreamExt;
///
/// async fn handler(extract::Body(body): extract::Body) {
/// async fn handler(Body(body): Body) {
/// // ...
/// }
///
@@ -275,7 +291,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::{body::Body, prelude::*, tests::*};
use crate::{body::Body, handler::post, route, tests::*};
use http::StatusCode;
#[tokio::test]
+6 -1
View File
@@ -11,7 +11,12 @@ use std::{convert::Infallible, ops::Deref};
/// # Example
///
/// ```rust,no_run
/// use axum::{extract::TypedHeader, prelude::*};
/// use axum::{
/// extract::TypedHeader,
/// handler::get,
/// route,
/// routing::RoutingDsl
/// };
/// use headers::UserAgent;
///
/// async fn users_teams_show(
+6 -2
View File
@@ -4,9 +4,11 @@
//!
//! ```
//! use axum::{
//! prelude::*,
//! extract::ws::{WebSocketUpgrade, WebSocket},
//! handler::get,
//! response::IntoResponse,
//! route,
//! routing::RoutingDsl
//! };
//!
//! let app = route("/ws", get(handler));
@@ -109,9 +111,11 @@ impl WebSocketUpgrade {
///
/// ```
/// use axum::{
/// prelude::*,
/// extract::ws::{WebSocketUpgrade, WebSocket},
/// handler::get,
/// response::IntoResponse,
/// route,
/// routing::RoutingDsl
/// };
///
/// let app = route("/ws", get(handler));