Using axum, change in function body, not signature, causes "trait not satisfied" error?

โš“ Rust    ๐Ÿ“… 2025-10-23    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

I have some code that uses the axum web app crate. Snippets below. The weird thing is that it compiled, without the await on send_dev_notification. Thatโ€™s a bug, so I added the await, and then it fails to compile with the error below.

Iโ€™m confused by two things.

  1. Itโ€™s telling me to use #[axum::debug_handler] when I already have.
  2. I changed the internals of a function inside another function called by send_daily_email, yet that somehow changed send_daily_email enough to trigger this error?

What is going on?

let admin_app = Router::new()        
        .route("/send-daily-email", post(send_daily_email))
        .with_state(pool.clone());
...

#[axum::debug_handler]
async fn send_daily_email(State(pool): State<PgPool>) -> String {
    let config = CONFIG.get().unwrap();
    let table = config.get("web-log-table").unwrap().as_str().unwrap();
    let res = job_watch::email_daily_summary(&pool, table).await;
    match res {
        Ok(_) => "OK".into(),
        Err(e) => "Error".into()
    }
}
pub async fn email_daily_summary(pool: &PgPool, log_table: &str) -> Result<(), Box<dyn std::error::Error>> {
    ...
    // was: email::send_dev_notification("Daily Server Summary", &body);
    email::send_dev_notification("Daily Server Summary", &body).await;
    Ok(())
}

Error:

error[E0277]: the trait bound `fn(State<Pool<Postgres>>) -> ... {send_daily_email}: Handler<_, _>` is not satisfied
   --> my-web-site/src/lib.rs:177:42
    |
177 |         .route("/send-daily-email", post(send_daily_email))
    |                                     ---- ^^^^^^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for fn item `fn(State<Pool<Postgres>>) -> ... {send_daily_email}`
    |                                     |
    |                                     required by a bound introduced by this call
    |
    = note: Consider using `#[axum::debug_handler]` to improve the error message
    = help: the following other types implement trait `Handler<T, S>`:
              `MethodRouter<S>` implements `Handler<(), S>`
              `axum::handler::Layered<L, H, T, S>` implements `Handler<T, S>`
note: required by a bound in `post`
   --> /Users/rob/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/axum-0.8.6/src/routing/method_routing.rs:445:1
    |
445 | top_level_handler_fn!(post, POST);
    | ^^^^^^^^^^^^^^^^^^^^^^----^^^^^^^
    | |                     |
    | |                     required by a bound in this function
    | required by this bound in `post`

4 posts - 2 participants

Read full topic

๐Ÿท๏ธ Rust_feed