lambda-fairy / maud

:pencil: Compile-time HTML templates for Rust
https://maud.lambda.xyz
Apache License 2.0
2.14k stars 142 forks source link

error[E0277]: the trait bound `PreEscaped<String>: Responder` is not satisfied #330

Closed g-cyan closed 2 years ago

g-cyan commented 2 years ago

In this page of Actix , I copied the codes.

https://maud.lambda.xyz/web-frameworks.html

use actix_web::{get, App, HttpServer, Result as AwResult};
use maud::{html, Markup};
use std::io;

#[get("/")]
async fn index() -> AwResult<Markup> {
    Ok(html! {
        html {
            body {
                h1 { "Hello World!" }
            }
        }
    })
}

#[actix_web::main]
async fn main() -> io::Result<()> {
    HttpServer::new(|| App::new().service(index))
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
}

The error spilled out as follows.

error[E0277]: the trait bound `PreEscaped<String>: Responder` is not satisfied
   --> src/main.rs:5:1
    |
5   | #[get("/")]
    | ^^^^^^^^^^^ the trait `Responder` is not implemented for `PreEscaped<String>`

What can I do for next?

lambda-fairy commented 2 years ago

Hi @g-cyan, sorry about the late reply.

What's the contents of your Cargo.toml and Cargo.lock? This usually happens when the actix-web version is not compatible. Or the feature is not enabled.

g-cyan commented 2 years ago

actix-web = "3.3.3" works perfectly so far with above code. I think the above error message is thrown as I had used version 4 of actix -web.

penso commented 2 years ago

I have the same issue with actix4.

penso commented 2 years ago

Note: adding the git repo fixed it.