diff options
author | Michael Alyn Miller <malyn@strangeGizmo.com> | 2021-11-27 20:59:51 -0800 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-11-27 22:03:18 -0800 |
commit | 4940b5dd5e792811491f1c3c3b1c70c8177c7e02 (patch) | |
tree | 4d28ad21a66ecf9496c265c0844b4c4d036763bc /askama_shared | |
parent | 3ef2869f48556a0aae4ca861889f9fd8bea02d66 (diff) | |
download | askama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.tar.gz askama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.tar.bz2 askama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.zip |
Add Axum integration
Diffstat (limited to 'askama_shared')
-rw-r--r-- | askama_shared/src/generator.rs | 18 | ||||
-rw-r--r-- | askama_shared/src/lib.rs | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 78ada4b..e121be5 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -96,6 +96,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { if self.integrations.actix { self.impl_actix_web_responder(&mut buf)?; } + if self.integrations.axum { + self.impl_axum_into_response(&mut buf)?; + } if self.integrations.gotham { self.impl_gotham_into_response(&mut buf)?; } @@ -222,6 +225,21 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { buf.writeln("}") } + // Implement Axum's `IntoResponse`. + fn impl_axum_into_response(&mut self, buf: &mut Buffer) -> Result<(), CompileError> { + self.write_header(buf, "::axum::response::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> {", + )?; + let ext = self.input.extension().unwrap_or("txt"); + buf.writeln(&format!("::askama_axum::into_response(&self, {:?})", ext))?; + buf.writeln("}")?; + buf.writeln("}") + } + // Implement gotham's `IntoResponse`. fn impl_gotham_into_response(&mut self, buf: &mut Buffer) -> Result<(), CompileError> { self.write_header(buf, "::askama_gotham::IntoResponse", None)?; diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index f217cfb..8d64e7b 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -274,6 +274,7 @@ pub fn get_template_source(tpl_path: &Path) -> std::result::Result<String, Compi #[derive(Clone, Copy, Debug)] pub struct Integrations { pub actix: bool, + pub axum: bool, pub gotham: bool, pub iron: bool, pub mendes: bool, |