std :: marker :: Unpin не выполняется - PullRequest
1 голос
/ 14 февраля 2020

Я пытаюсь заставить работать фьючерсную функцию try_join_all, и я немного застрял. Мой код выглядит следующим образом:

use crate::Client;
use futures::future;
use std::boxed;

const SQL_EXTENSION: &str = "sql";

type ExecuteFileFuture = boxed::Box<dyn future::Future<Output = Result<(), postgres::Error>>>;

pub async fn run_migrations_in_path(
    path: &str,
    client: &mut Client,
) -> Result<(), postgres::Error> {
    let sql_files = files::by_extension(path, SQL_EXTENSION);
    let transaction = client.transaction().await?;
    let migrations: Vec<ExecuteFileFuture> = sql_files
        .iter()
        .map(|file_path| boxed::Box::new(client.execute_file(file_path)) as ExecuteFileFuture)
        .collect();
    future::try_join_all(migrations).await?;
    transaction.commit()
}

Когда я пытаюсь запустить этот код, я получаю следующие ошибки:

error[E0277]: the trait bound `dyn core::future::future::Future<Output
= std::result::Result<(), tokio_postgres::error::Error>>: std::marker::Unpin` is not satisfied    --> src/migrate.rs:19:26
    | 19  |     future::try_join_all(tasks).await?;
    |                          ^^^^^ the trait `std::marker::Unpin` is not implemented for `dyn core::future::future::Future<Output =
std::result::Result<(), tokio_postgres::error::Error>>`
    |     ::: /home/moon/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.4/src/future/try_join_all.rs:126:14
    | 126 |     I::Item: TryFuture,
    |              --------- required by this bound in `futures_util::future::try_join_all::try_join_all`
    |
    = note: required because of the requirements on the impl of `core::future::future::Future` for `std::boxed::Box<dyn
core::future::future::Future<Output = std::result::Result<(),
tokio_postgres::error::Error>>>`
    = note: required because of the requirements on the impl of `futures_core::future::TryFuture` for `std::boxed::Box<dyn
core::future::future::Future<Output = std::result::Result<(),
tokio_postgres::error::Error>>>`

error[E0277]: the trait bound `dyn core::future::future::Future<Output
= std::result::Result<(), tokio_postgres::error::Error>>: std::marker::Unpin` is not satisfied   --> src/migrate.rs:19:5    | 19
|     future::try_join_all(tasks).await?;    |    
^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not
implemented for `dyn core::future::future::Future<Output =
std::result::Result<(), tokio_postgres::error::Error>>`    |    =
note: required because of the requirements on the impl of
`core::future::future::Future` for `std::boxed::Box<dyn
core::future::future::Future<Output = std::result::Result<(),
tokio_postgres::error::Error>>>`    = note: required because of the
requirements on the impl of `futures_core::future::TryFuture` for
`std::boxed::Box<dyn core::future::future::Future<Output =
std::result::Result<(), tokio_postgres::error::Error>>>`    = note:
required by `futures_util::future::try_join_all::TryJoinAll`

error[E0277]: the trait bound `dyn core::future::future::Future<Output
= std::result::Result<(), tokio_postgres::error::Error>>: std::marker::Unpin` is not satisfied   --> src/migrate.rs:19:5    | 19
|     future::try_join_all(tasks).await?;    |    
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is
not implemented for `dyn core::future::future::Future<Output =
std::result::Result<(), tokio_postgres::error::Error>>`    |    =
note: required because of the requirements on the impl of
`core::future::future::Future` for `std::boxed::Box<dyn
core::future::future::Future<Output = std::result::Result<(),
tokio_postgres::error::Error>>>`    = note: required because of the
requirements on the impl of `futures_core::future::TryFuture` for
`std::boxed::Box<dyn core::future::future::Future<Output =
std::result::Result<(), tokio_postgres::error::Error>>>`

Я просматриваю форумы et c, но пока не удалось решить проблему. Я надеюсь, что кто-то может пролить некоторый свет, так как я не уверен, в чем проблема.

Заранее спасибо за любую помощь!

...