diff options
author | Michael Alyn Miller <malyn@strangeGizmo.com> | 2021-12-04 16:49:06 -0800 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-12-05 10:00:02 +0100 |
commit | d77553d826f3c90999e0dd84f35cac3690c3d0ca (patch) | |
tree | 1e85deec731e92dbaca13a00c530f86ebefeeeaf | |
parent | e0daa9b83a1a69ff955333eed8c0dddb0f438aaf (diff) | |
download | askama-d77553d826f3c90999e0dd84f35cac3690c3d0ca.tar.gz askama-d77553d826f3c90999e0dd84f35cac3690c3d0ca.tar.bz2 askama-d77553d826f3c90999e0dd84f35cac3690c3d0ca.zip |
Update axum to 0.4 (by switching to axum-core)
-rw-r--r-- | askama_axum/Cargo.toml | 8 | ||||
-rw-r--r-- | askama_axum/src/lib.rs | 17 | ||||
-rw-r--r-- | askama_shared/src/generator.rs | 8 |
3 files changed, 17 insertions, 16 deletions
diff --git a/askama_axum/Cargo.toml b/askama_axum/Cargo.toml index 7d3045d..998f54a 100644 --- a/askama_axum/Cargo.toml +++ b/askama_axum/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "askama_axum" version = "0.10.0" -authors = ["Michael Alyn Miller <malyn@strangeGizmo.com>"] edition = "2018" description = "Axum integration for Askama templates" keywords = ["markup", "template", "jinja2", "html", "axum"] @@ -14,10 +13,13 @@ workspace = ".." readme = "README.md" [dependencies] -askama = { version = "0.11.0-beta.1", path = "../askama", default-features = false, features = ["with-axum", "mime", "mime_guess"] } -axum = { version = "0.3", default-features = false } +askama = { version = "0.11.0", path = "../askama", default-features = false, features = ["with-axum", "mime", "mime_guess"] } +axum-core = "0.1" +http = "0.2" +http-body = "0.4" [dev-dependencies] +axum = { version = "0.4", default-features = false } hyper = { version = "0.14", features = ["full"] } tokio = { version = "1.0", features = ["full"] } tower = { version = "0.4", features = ["util"] }
\ No newline at end of file diff --git a/askama_axum/src/lib.rs b/askama_axum/src/lib.rs index 0c21464..859b19e 100644 --- a/askama_axum/src/lib.rs +++ b/askama_axum/src/lib.rs @@ -1,13 +1,14 @@ #![deny(elided_lifetimes_in_paths)] pub use askama::*; -use axum::{ - self, - body::{Bytes, Full}, - http::{Response, StatusCode}, -}; +use axum_core::body; +pub use axum_core::body::BoxBody; +pub use axum_core::response::IntoResponse; +pub use http::Response; +use http::StatusCode; +use http_body::{Empty, Full}; -pub fn into_response<T: Template>(t: &T, ext: &str) -> axum::http::Response<Full<Bytes>> { +pub fn into_response<T: Template>(t: &T, ext: &str) -> Response<BoxBody> { match t.render() { Ok(body) => Response::builder() .status(StatusCode::OK) @@ -15,11 +16,11 @@ pub fn into_response<T: Template>(t: &T, ext: &str) -> axum::http::Response<Full "content-type", askama::mime::extension_to_mime_type(ext).to_string(), ) - .body(body.into()) + .body(body::boxed(Full::from(body))) .unwrap(), Err(_) => Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR) - .body(vec![].into()) + .body(body::boxed(Empty::new())) .unwrap(), } } diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 368db9f..738b878 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -227,12 +227,10 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { // Implement Axum's `IntoResponse`. fn impl_axum_into_response(&mut self, buf: &mut Buffer) -> Result<(), CompileError> { - self.write_header(buf, "::axum::response::IntoResponse", None)?; + self.write_header(buf, "::askama_axum::IntoResponse", None)?; buf.writeln( - "type Body = ::axum::body::Full<::axum::body::Bytes>;\n\ - type BodyError = std::convert::Infallible;\n\ - fn into_response(self)\ - -> ::axum::http::Response<Self::Body> {", + "fn into_response(self)\ + -> ::askama_axum::Response<::askama_axum::BoxBody> {", )?; let ext = self.input.extension().unwrap_or("txt"); buf.writeln(&format!("::askama_axum::into_response(&self, {:?})", ext))?; |