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
This commit is contained in:
parent
2f6f781dc7
commit
6e3222f57a
5 changed files with 13 additions and 16 deletions
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
- Remove blanket `Render` impl for `T: Display`
|
- Remove blanket `Render` impl for `T: Display`
|
||||||
[#320](https://github.com/lambda-fairy/maud/pull/320)
|
[#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
|
## [0.23.0] - 2021-11-10
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ This then allows you to use it directly as a response!
|
||||||
|
|
||||||
```rust,no_run
|
```rust,no_run
|
||||||
use maud::{html, Markup};
|
use maud::{html, Markup};
|
||||||
use axum::{Router, handler::get};
|
use axum::{Router, routing::get};
|
||||||
|
|
||||||
async fn hello_world() -> Markup {
|
async fn hello_world() -> Markup {
|
||||||
html! {
|
html! {
|
||||||
|
|
|
@ -13,7 +13,7 @@ rocket = "0.4"
|
||||||
rouille = "3"
|
rouille = "3"
|
||||||
tide = "0.16"
|
tide = "0.16"
|
||||||
tokio = { version = "1.9.0", features = ["rt", "macros", "rt-multi-thread"] }
|
tokio = { version = "1.9.0", features = ["rt", "macros", "rt-multi-thread"] }
|
||||||
axum = "0.2"
|
axum = "0.4"
|
||||||
|
|
||||||
[dependencies.async-std]
|
[dependencies.async-std]
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
|
|
|
@ -13,6 +13,7 @@ edition = "2021"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
axum = ["axum-core", "http"]
|
||||||
|
|
||||||
# Web framework integrations
|
# Web framework integrations
|
||||||
actix-web = ["actix-web-dep", "futures-util"]
|
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 }
|
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 }
|
actix-web-dep = { package = "actix-web", version = ">= 2, < 4", optional = true, default-features = false }
|
||||||
tide = { version = "0.16.0", 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]
|
[dev-dependencies]
|
||||||
trybuild = { version = "1.0.33", features = ["diff"] }
|
trybuild = { version = "1.0.33", features = ["diff"] }
|
||||||
|
|
|
@ -296,24 +296,17 @@ mod tide_support {
|
||||||
mod axum_support {
|
mod axum_support {
|
||||||
use crate::PreEscaped;
|
use crate::PreEscaped;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use axum::{
|
use axum_core::{body::BoxBody, response::IntoResponse};
|
||||||
body::Body,
|
use http::{header, HeaderMap, HeaderValue, Response};
|
||||||
http::{header, HeaderValue, Response, StatusCode},
|
|
||||||
response::IntoResponse,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl IntoResponse for PreEscaped<String> {
|
impl IntoResponse for PreEscaped<String> {
|
||||||
type Body = Body;
|
fn into_response(self) -> Response<BoxBody> {
|
||||||
type BodyError = <Self::Body as axum::body::HttpBody>::Error;
|
let mut headers = HeaderMap::new();
|
||||||
|
headers.insert(
|
||||||
fn into_response(self) -> Response<Body> {
|
|
||||||
let mut res = Response::new(Body::from(self.0));
|
|
||||||
*res.status_mut() = StatusCode::OK;
|
|
||||||
res.headers_mut().insert(
|
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
HeaderValue::from_static("text/html; charset=utf-8"),
|
HeaderValue::from_static("text/html; charset=utf-8"),
|
||||||
);
|
);
|
||||||
res
|
(headers, self.0).into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue