首页  >  问答  >  正文

特征绑定“FieldAttr:ToTokens”不满足:错误

我想在 EC2(fargate) 上部署 Dockerfile 版本。 我在cloudwatch中遇到以下错误。 “创建池失败。:错误(无)” 我已经想出了解决这个问题的办法。 我在建立连接时将方法从 build 更改为 build_unchecked

但是,我收到以下错误并且无法编译。

error[E0277]: the trait bound `FieldAttr: ToTokens` is not satisfied
   --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/diesel_derives-2.0.1/src/attrs.rs:143:18
    |
143 | impl Spanned for FieldAttr {
    |                  ^^^^^^^^^ the trait `ToTokens` is not implemented for `FieldAttr`
    |
    = help: the following other types implement trait `ToTokens`:
              &'a T
              &'a mut T
              Abi
              Abstract
              AndAnd
              AndEq
              AngleBracketedGenericArguments
              Arm
            and 312 others
    = note: required for `FieldAttr` to implement `quote::spanned::private::Sealed`
note: required by a bound in `quote::spanned::Spanned`
   --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/quote-1.0.25/src/spanned.rs:6:20
    |
6   | pub trait Spanned: private::Sealed {
    |                    ^^^^^^^^^^^^^^^ required by this bound in `Spanned`

error[E0277]: the trait bound `StructAttr: ToTokens` is not satisfied
   --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/diesel_derives-2.0.1/src/attrs.rs:242:18
    |
242 | impl Spanned for StructAttr {
    |                  ^^^^^^^^^^ the trait `ToTokens` is not implemented for `StructAttr`
    |
    = help: the following other types implement trait `ToTokens`:
              &'a T
              &'a mut T
              Abi
              Abstract
              AndAnd
              AndEq
              AngleBracketedGenericArguments
              Arm
            and 312 others
    = note: required for `StructAttr` to implement `quote::spanned::private::Sealed`
note: required by a bound in `quote::spanned::Spanned`
   --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/quote-1.0.25/src/spanned.rs:6:20
    |
6   | pub trait Spanned: private::Sealed {
    |                    ^^^^^^^^^^^^^^^ required by this bound in `Spanned`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `diesel_derives` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `practice-rust v0.1.0 (/usr/src/practice-rust)`, intermediate artifacts can be found at `/usr/src/practice-rust/target`
pub type Pool = r2d2::Pool<ConnectionManager<MysqlConnection>>;

pub fn establish_connection() -> Pool {
    dotenv().ok();

    std::env::set_var("RUST_LOG", "actix_web=debug");
    let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");


    let manager = ConnectionManager::<MysqlConnection>::new(database_url);
    let pool: Pool = r2d2::Pool::builder().build_unchecked(manager);
    pool
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {

    let pool = db::establish_connection();
    HttpServer::new(move|| {
        App::new()
        .app_data(Data::new(pool.clone()))
        .service(todo_index)
    })
    .bind("0.0.0.0:8080")?
    .run()
    .await
}
#[get("/api/todo")]
async fn todo_index(db: web::Data<db::Pool>) -> impl Responder {

    let mut conn = db.get().unwrap();
    let todo = schema::todos::table
        .load::<model::Todo>(&mut conn)
        .expect("Error not showing todo list");

    HttpResponse::Ok().json(todo)
}

我尝试了引用传递,但没有成功。

无需修改即可构建另一个 Dockerfile。 问题出在 Dockerfile 中。

dev:构建完成。

FROM rust:1-slim-buster

RUN apt-get update \
    && apt-get install -y default-libmysqlclient-dev mariadb-client

WORKDIR /usr/src/myapp/practice-rust
COPY . .

stg:无法构建。

FROM rust:1-slim-buster as builder

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    default-libmysqlclient-dev mariadb-client \
    && apt-get -y clean \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/practice-rust
COPY . .

RUN cargo install --path .

FROM debian:10.13-slim as stage

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    default-libmysqlclient-dev mariadb-client \
    && apt-get -y clean \
    && rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/local/cargo/bin/practice-rust /usr/local/bin/practice-rust
CMD [ "practice-rust"]

P粉696891871P粉696891871206 天前320

全部回复(2)我来回复

  • P粉545910687

    P粉5459106872024-03-28 08:08:07

    嘿,我刚刚通过更新这些依赖项遇到了同样的错误:

    https://github.com/nxthat/nanocl/commit/6b7b19d7ff50d9392b1e56ec1ad67c34ea63 c632

    也许您可以通过降级某些依赖项来快速修复?

    我也想知道是什么问题

    回复
    0
  • P粉659378577

    P粉6593785772024-03-28 00:20:39

    我认为这是由于“引用”的重大变化而发生的 问题链接

    回复
    0
  • 取消回复