简体   繁体   中英

Illogical `mismatched types` in Rust

Seeking your support which I have illogical mismatched types in our project.

Project built by docker compose up . Actually images working fine from 3-4 months without issues; but now it shows error as illustrated below.

Sample Error (Note it is happened many times):

error[E0308]: mismatched types
   --> db/src/pg/user_profiles.rs:158:27
    |
158 |             &[&is_worker, &*user_id],
    |                           ^^^^^^^^^ expected `bool`, found `i64`
    |
    = note: expected reference `&bool`
               found reference `&i64`

Code snippet for this error as below:

pub struct UserId(pub i64);
pub async fn update_is_worker(user_id: UserId, is_worker: bool) -> Result<()> {
    let client = PG_POOL.get().await?;
    let stmt = client
        .prepare_typed(
            "\
        UPDATE user_profiles \
        SET \
            is_worker = $1 \
        WHERE user_id = $2;\
        ",
            &[Type::BOOL, Type::INT8],
        )
        .await?;

    client.execute(&stmt, &[&is_worker, &*user_id]).await?;

    Ok(())
}

I got a solution for this in the Rust server @ Discord from skeletizzle which he asked me to edit line as below: client.execute(&stmt, &[&is_worker as _, &*user_id as _]).await?;

I have a lot of these errors, so I did change similar lines with same error with same concept.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM