需要Rust unzip()类型注解

rn0zuynd  于 2023-04-06  发布在  其他
关注(0)|答案(1)|浏览(147)

我尝试解压缩嵌套元组并使用组合子来完成:

let create_task = |msg| {
    // We need to keep the message_id to report failures to SQS
    // and the receipt_handle to delete the processed messages from SQS.
    let SqsMessageObj {
        message_id,
        body,
        receipt_handle,
        ..
    } = msg;

    let span = tracing::span!(tracing::Level::INFO, "Handling SQS msg", message_id);
    let task = async {
        let item = serde_json::from_value(body)?;
        f(item, app_config).await
    };

    (
        (
            message_id.unwrap_or_default(),
            receipt_handle.unwrap_or_default(),
        ),
        task,
    )
};

print!("{:?}", event.payload);

let ((ids, receipts), tasks): ((_, _), _) = event
    .payload
    .records
    .into_iter()
    .map(create_task)
    .unzip::<(_, _), _, (_, _), _>();

编译器对此不满意。unzip()类型的注解应该是什么?

vfh0ocws

vfh0ocws1#

这是通过对所有元组元素使用Vec<_>类型来完成的:

let ((ids, receipts), tasks): ((Vec<_>, Vec<_>), Vec<_>) = event.payload.records.into_iter().map(create_task).unzip();

相关问题