From 6e3222f57adfc35dddba00f680cb2fc9cc7238f4 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Wed, 8 Dec 2021 09:12:00 +0100 Subject: [PATCH] Update to axum-core 0.1 (#325) * Update to axum-core 0.1 Together with the new 0.4 release of `axum` we made a new crate called [`axum-core`]. `axum-core` has a small API and is less likely to receive breaking changes. Therefore its recommended for libraries to depend on `axum-core` instead of `axum`. So this updates `maud` to use `axum-core`. Note this is a breaking change since `axum-core` requires `axum` 0.4. [`axum-core`]: https://crates.io/crates/axum-core * Update changelog link * fix test --- CHANGELOG.md | 2 ++ docs/content/web-frameworks.md | 2 +- doctest/Cargo.toml | 2 +- maud/Cargo.toml | 4 +++- maud/src/lib.rs | 19 ++++++------------- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d036c48..596d9e9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Remove blanket `Render` impl for `T: Display` [#320](https://github.com/lambda-fairy/maud/pull/320) +- Update to axum-core 0.1. This requires axum 0.4 + [#325](https://github.com/lambda-fairy/maud/pull/325) ## [0.23.0] - 2021-11-10 diff --git a/docs/content/web-frameworks.md b/docs/content/web-frameworks.md index 7730d9b0..8c52fb09 100644 --- a/docs/content/web-frameworks.md +++ b/docs/content/web-frameworks.md @@ -159,7 +159,7 @@ This then allows you to use it directly as a response! ```rust,no_run use maud::{html, Markup}; -use axum::{Router, handler::get}; +use axum::{Router, routing::get}; async fn hello_world() -> Markup { html! { diff --git a/doctest/Cargo.toml b/doctest/Cargo.toml index 82a990eb..fb8d674d 100644 --- a/doctest/Cargo.toml +++ b/doctest/Cargo.toml @@ -13,7 +13,7 @@ rocket = "0.4" rouille = "3" tide = "0.16" tokio = { version = "1.9.0", features = ["rt", "macros", "rt-multi-thread"] } -axum = "0.2" +axum = "0.4" [dependencies.async-std] version = "1.9.0" diff --git a/maud/Cargo.toml b/maud/Cargo.toml index 33c54ba8..45c9ef94 100644 --- a/maud/Cargo.toml +++ b/maud/Cargo.toml @@ -13,6 +13,7 @@ edition = "2021" [features] default = [] +axum = ["axum-core", "http"] # Web framework integrations actix-web = ["actix-web-dep", "futures-util"] @@ -24,7 +25,8 @@ rocket = { version = ">= 0.3, < 0.5", optional = true } futures-util = { version = "0.3.0", optional = true, default-features = false } actix-web-dep = { package = "actix-web", version = ">= 2, < 4", optional = true, default-features = false } tide = { version = "0.16.0", optional = true, default-features = false } -axum = { version = "0.2", optional = true } +axum-core = { version = "0.1", optional = true } +http = { version = "0.2", optional = true } [dev-dependencies] trybuild = { version = "1.0.33", features = ["diff"] } diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 364e21d2..c2c0beaa 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -296,24 +296,17 @@ mod tide_support { mod axum_support { use crate::PreEscaped; use alloc::string::String; - use axum::{ - body::Body, - http::{header, HeaderValue, Response, StatusCode}, - response::IntoResponse, - }; + use axum_core::{body::BoxBody, response::IntoResponse}; + use http::{header, HeaderMap, HeaderValue, Response}; impl IntoResponse for PreEscaped { - type Body = Body; - type BodyError = ::Error; - - fn into_response(self) -> Response { - let mut res = Response::new(Body::from(self.0)); - *res.status_mut() = StatusCode::OK; - res.headers_mut().insert( + fn into_response(self) -> Response { + let mut headers = HeaderMap::new(); + headers.insert( header::CONTENT_TYPE, HeaderValue::from_static("text/html; charset=utf-8"), ); - res + (headers, self.0).into_response() } } }