rust - 如何将reqwest流转换为actix流?

标签 rust rust-tokio

我正在尝试将流从reqwest转换为actix响应的流,以避免在内存中创建较大的Vec:

use actix_web::{web, HttpRequest, HttpResponse, Responder};

pub async fn test(
    req: HttpRequest
) -> impl Responder {
    let request = reqwest::get("https://www.rust-lang.org").await;
    if request.is_err() {
        println!("Error: {:?}", request.err());
    }
    let request = request.unwrap();
    let stream = request.bytes_stream();

    HttpResponse::Ok()
        .content_type("text/html")
        .streaming(stream)
}

编译器给我:

  --> src/routes/test.rs:97:10
   |
97 |         .streaming(stream)
   |          ^^^^^^^^^ the trait `actix_http::error::ResponseError` is not implemented for `reqwest::error::Error`
   |
   = note: required because of the requirements on the impl of `std::convert::From<reqwest::error::Error>` for `actix_http::error::Error`
   = note: required because of the requirements on the impl of `std::convert::Into<actix_http::error::Error>` for `reqwest::error::Error`

我已经尽力而为:
  • 创建传递的Stream(甚至不编译,我也不擅长转换类型)
  • 实现了Reqwest错误的丢失错误(该错误不是公开的,所以我无法做到)
  • 尝试尝试(但不确定我是否使用正确)
  • 最佳答案

    我写了一个薄层来链接两个系统,传递错误类型:
    https://github.com/clia/reqwest-actix-stream

    关于rust - 如何将reqwest流转换为actix流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61069167/

    相关文章:

    rust - 为什么要尝试!()和?在不返回选项或结果的函数中使用时无法编译?

    rust - 如何在 tokio_core::io::Codec::decode(...) 中实现零拷贝?

    rust - hyper 与 bb8 和 postgres 的使用示例

    rust - 什么是 futures::future::lazy?

    rust - 如何使用reqwest执行并行异步HTTP GET请求?

    rust - 东京回声服务器。不能在同一个 future 读写

    variables - 为什么存在下划线前缀变量?

    rust - 奇怪的错误 : use of partially moved value

    rust - 尽管已实现,但尚未实现特征Serialize?

    rust - 显式返回借用引用的匹配语句