robertwayne / axum-htmx

A set of htmx extractors, responders, and request guards for axum.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example chunk of code in README 'HxResponseTrigger' didn't working

Moanrisy opened this issue · comments

// When we load our page, we will trigger any event listeners for "my-event.
async fn index() -> (&'static str, HxResponseTrigger) {
    (
        "Hello, world!",
        HxResponseTrigger::normal(["my-event", "second-event"]),
    )
}

error on here
.route("/index", get(index))

 │     the trait bound `fn() -> impl std::future::Future<Output = (&'static str, axum_htmx::HxResponseTrigger)> {index}: axum::handler::Handler<_, _>` is not satisfied rustc (E0277) [15, 30]
 │      the following other types implement trait `axum::handler::Handler<T, S>`: 
 │        <axum::handler::Layered<L, H, T, S> as axum::handler::Handler<T, S>> 
 │        <axum::routing::MethodRouter<S> as axum::handler::Handler<(), S>> 
 │     required by a bound introduced by this call rustc (E0277) [15, 26]

my dependencies
[dependencies]

axum = "0.7.2"
axum-htmx = "0.5.0"
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
tower-livereload = "0.9.1"
commented

Hey, thanks for pointing this out.

This is because HxResponseTrigger only impls IntoResponseParts, and we need to pass that before the body would consume (in this case).

I've updated the README with the correct code - I also made a note of this in the documentation!

use axum_htmx::HxResponseTrigger;

async fn index() -> (HxResponseTrigger, &'static str) {
    (
        HxResponseTrigger::normal(["my-event", "second-event"]),
        "Hello, world!",
    )
}