-
-
Notifications
You must be signed in to change notification settings - Fork 214
Axum documentation states askama_axum import is required, but it's not? #999
Description
Hi, consider this as much a question as an issue report. I am quite new to the Rust ecosystem, so forgive me if this comes across as a tad ignorant. The documentation for the Axum integration states:
In your template definitions, replace
askama::Templatewithaskama_axum::Template.
However, when I have both askama and askama_axum installed, I can also use the 'regular' askama::Template without getting any compilation issues. For example:
use askama::Template;
use axum::{routing::get, Router};
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let app = Router::new().route("/", get(index));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate {}
async fn index() -> IndexTemplate {
IndexTemplate {}
}Is this intended to work as such, and is it ok to keep using it like this? Why would one need to use asaka_axum and what extra does it do on top of the regular template?
I am also interested in how Cargo manages dependencies. If I install askama_axum I can see that askama is listed as a dependency, so I would expect that if I list askama_axum as the only dependency in Cargo.toml, it would also bring axum along.
However, if I modify the code above to use askama_axum::Template as the documentation states, and only install askama_axum, then I get the following compilation error:
error[E0433]: failed to resolve: could not find `askama` in the list of imported crates
--> src/main.rs:14:10
|
14 | #[derive(Template)]
| ^^^^^^^^ could not find `askama` in the list of imported crates
|
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
This is strange because Template is imported from askama_axum and not askama. But it leads me to believe that I need to have both askama_axum and askama listed in Cargo.toml, even though my code does not directly depend on askama. Is this intentional behavior? Should I be listing both? If so, why is askama not pulled in with askama_axum?
Again, total novice here. Feel free to close this issue if it's too much of a hassle to answer. Thanks in advance.