-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example for axum #118
Add example for axum #118
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks good. One very minor nitpick (it says warp rather than axum in the example text).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. Now I've found the time to look closer at the code. Looks good, I'll merge it soonish.
@@ -0,0 +1,29 @@ | |||
use axum::response::{Html, IntoResponse}; | |||
|
|||
macro_rules! render { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool macro! Simple enough, rather different from what the other examples do, but I like it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually the same macro as used in the actix example. I didn't investigate further but it seemed the actix example did duplicate one branch in the macro. Here is the macro from actix:
macro_rules! render {
($template:path) => (Render(|o| $template(o)));
($template:path, $($arg:expr),*) => {{
use actix_ructe::Render;
Render(|o| $template(o, $($arg),*))
}};
($template:path, $($arg:expr),* ,) => {{
use actix_ructe::Render;
Render(|o| $template(o, $($arg),*))
}};
}
I'm not too deep into Rust macros so I don't know what the trailing ,
in tha last branch of the macro changes in comparison to the second branch but it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'd forgotten all about that macro. Ah well. 😎
The trailing comma is to match invocations where this is a trailing comma after the last argument, as is common if the argument list is long enogh to be split on more than one line, like
render!(
the_template,
one_argument,
another_argument, // <-- here
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. I think I found a less redundant way by making the trailing comma optional. See cf68d54
* Removed backwards compatible aliases for template functions. In ructe 0.7.2 and earlier, a template file `page.rs.html` resulted in a rust function `templates::page(...)`. In 0.7.2, that was changed to `templates::page_html(...)` and the old name was kept as a deprecated alias. However, since the template functions are usually defined within the same crate that defines them, the deprecation warning has usually not been shown, and this removal may still be a surprise to some users (it was even used in examples up to this change). * Allow more lifetime arguments to templates in template arguments (PR #122, fixes #121). Thanks to @wezm! * Added axum example (PR #118). Thanks to @vbrandl! * Updated rsass to 0.27.0 and base64 to 0.21.0. * Updated dependencies in examples: actix-web 4.2.1, axum 0.6.2, env_logger 0.10.0, * Dropped support for rust edition 2015 in crates that directly uses ructe.
I added an example on how to use ructe with the axum framework.
The example should behave exactly the same as the actix example