djc / askama

Type-safe, compiled Jinja-like templates for Rust
Apache License 2.0
3.51k stars 221 forks source link

Error when use askama0.11.0 and actix-web #586

Open ghost opened 2 years ago

ghost commented 2 years ago

main.rs

use actix_web::{get, Responder, HttpServer, App};
use askama_actix::Template;

#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate<'a> {
    title: &'a str,
}

#[get("/")]
async fn hello() -> impl Responder {
    IndexTemplate { title: "Any fun in CooeeU" }
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    println!("Hello, world!");
    HttpServer::new(|| {
        App::new()
            .service(hello)
    })
    .bind("0.0.0.0:6543")?
    .run()
    .await
}

These dependencies have the following error.

Cargo.toml

[dependencies]
env_logger = "0.9.0"
actix-web = { version = "3.3.3", default-features = false }
askama = { version = "0.11.0", default-features = false, features = ["with-actix-web"] }
askama_actix = { version = "0.11.1", default-features = false }

Error

error[E0407]: method `extension` is not a member of trait `askama::Template`
 --> src/main.rs:4:10
  |
4 | #[derive(Template)]
  |          ^^^^^^^^ not a member of trait `askama::Template`
  |
  = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0407]: method `size_hint` is not a member of trait `askama::Template`
 --> src/main.rs:4:10
  |
4 | #[derive(Template)]
  |          ^^^^^^^^ not a member of trait `askama::Template`
  |
  = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0405]: cannot find trait `SizedTemplate` in crate `askama`
 --> src/main.rs:4:10
  |
4 | #[derive(Template)]
  |          ^^^^^^^^ not found in `askama`
  |
  = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this trait
  |
1 | use askama_actix::SizedTemplate;
  |

Some errors have detailed explanations: E0405, E0407.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `cfunw` due to 3 previous errors

And when I change dependencies as below.It's build with no error.

Cargo.toml

[dependencies]
env_logger = "0.9.0"
actix-web = { version = "3.3.3", default-features = false }
askama = { version = "0.10.5", default-features = false, features = ["with-actix-web"] }
askama_actix = { version = "0.11.1", default-features = false }

Build result

......
   Compiling actix-router v0.2.7
   Compiling actix-connect v2.0.0
   Compiling actix-http v2.2.1
   Compiling askama v0.10.5
   Compiling awc v2.0.3
   Compiling actix-web v3.3.3
   Compiling askama_actix v0.11.1
   Compiling cfunw v0.1.0 (/data/julian/CooeeUProjects/apps/cfunw)
    Finished dev [unoptimized + debuginfo] target(s) in 23.03s

I think the new version have same problem.

djc commented 2 years ago

Try #584?