Mismatched types error in generic code

⚓ rust    📅 2025-06-18    👤 surdeus    👁️ 2      

surdeus

I've been trying to generalize a function to accept an sqlx::Executor. This is what I came up with:

pub async fn create_sign_request<'e, 'c: 'e, E>(
    executor: &'e E,
    params: SignRequestParams,
) -> Result<SignRequest>
where
    &'e E: SqliteExecutor<'c>,
{
    let record = sqlx::query_file_as!(
        SignRequest,
        "sql/insert_sign_request.sql",
        params.id,
        params.kind,
        params.url,
        params.timeout
    )
    .fetch_one(executor)
    .await
    .context("insert signing request")?;

    sqlx::query_file!("sql/insert_pending_request.sql", params.id)
        .execute(executor)
        .await
        .context("insert pending request")?;

    Ok(record)
}

This works nice when passed &Pool<Sqlite>. But when passed &mut SqliteConnection it yells at me with:

error[E0308]: mismatched types
  --> src/bin/signer-webapi/handlers/sign.rs:45:17
   |
44 |             let record = signer::db::create_sign_request(
   |                          ------------------------------- arguments to this function are incorrect
45 |                 &mut *txn,
   |                 ^^^^^^^^^ expected `&Pool<Sqlite>`, found `&mut SqliteConnection`
   |
   = note:      expected reference `&Pool<Sqlite>`
           found mutable reference `&mut SqliteConnection`

Why is the compiler expecting &Pool<Sqlite> where no place in the function definition even mentions this type?

3 posts - 3 participants

Read full topic

🏷️ rust_feed