我有一个rusoto_core::ByteStream
实现期货Stream
特征的方法:
let chunks = vec![b"1234".to_vec(), b"5678".to_vec()];
let stream = ByteStream::new(stream::iter_ok(chunks));
我想将它传递给actix_web 的HttpResponseBuilder::streaming
方法。
use actix_web::dev::HttpResponseBuilder; // 0.7.18
use rusoto_core::ByteStream; // 0.36.0
fn example(stream: ByteStream, builder: HttpResponseBuilder) {
builder.streaming(stream);
}
当我尝试这样做时,我收到以下错误:
error[E0271]: type mismatch resolving `<rusoto_core::stream::ByteStream as futures::stream::Stream>::Item == bytes::bytes::Bytes`
--> src/main.rs:5:13
|
5 | builder.streaming(stream);
| ^^^^^^^^^ expected struct `std::vec::Vec`, found struct `bytes::bytes::Bytes`
|
= note: expected type `std::vec::Vec<u8>`
found type `bytes::bytes::Bytes`
我相信原因是streaming()
期望 a S: Stream<Item = Bytes, Error>
(ie, Item = Bytes
) 但我ByteStream
有Item = Vec<u8>
. 我该如何解决?
我认为解决方案以某种方式解决了flatmap
我的问题,ByteStream
但我找不到这样的流方法。
这是一个如何使用的示例streaming()
:
let text = "123";
let (tx, rx_body) = mpsc::unbounded();
let _ = tx.unbounded_send(Bytes::from(text.as_bytes()));
HttpResponse::Ok()
.streaming(rx_body.map_err(|e| error::ErrorBadRequest("bad request")))