我正在尝试将流从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
(甚至不编译,我也不擅长转换类型)最佳答案
我写了一个薄层来链接两个系统,传递错误类型:
https://github.com/clia/reqwest-actix-stream
关于rust - 如何将reqwest流转换为actix流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61069167/