lambda-fairy / maud

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

Axum error[E0277]: the trait bound `fn() -> impl Future<Output = PreEscaped<String>> {a}: Handler<_, _>` is not satisfied #334

Closed alleyshairu closed 2 years ago

alleyshairu commented 2 years ago

For some reason I can't make it work with axum version 0.4. I have followed the instructions provided in the framework integrations section, but it still doesn't work.

Dependencies in Cargo.toml are as follows.

[dependencies]
axum = { version="0.4"}
maud = { version="*", features = ["axum"]}
tokio = { version="1.0", features = ["full"]}

Nothing special in code, just a starter hello world example.

use axum::{routing::get, Router};
use maud::{html, Markup};

async fn hello_world() -> &'static str {
    "hello"
}

async fn a() -> Markup {
    html! {
        h1 { "Hello, World!" }
    }
}

#[tokio::main]
async fn main() {
    // build our application with a single route
    let app = Router::new().route("/", get(a));

    // run it with hyper on localhost:3000
    axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
        .serve(app.into_make_service())
        .await
        .unwrap();
} 

Also, maud and axum works fine If I change axum version to 0.2 and use the axum::handler::get handler.

lambda-fairy commented 2 years ago

Hi @alleyshairu, Axum 0.4 support is available in the repo but not released yet. In the meantime you can depend on the git repo directly:

maud = { git = "https://github.com/lambda-fairy/maud", features = ["axum"] }
alleyshairu commented 2 years ago

Thanks a lot! It worked. Feeling super embarrassed at the moment.