reqwest_streams/
protobuf_body.rs1use crate::stream_body::{ReqwestStreamBody, StreamBodyRequest};
4use futures::Stream;
5use http_streams_core::ProtobufStreamFormat;
6
7pub trait ProtobufStreamRequest {
11 fn protobuf_stream_body<S, T>(self, stream: S) -> reqwest::RequestBuilder
14 where
15 T: prost::Message + Send + 'static,
16 S: Stream<Item = T> + Send + 'static;
17
18 fn try_protobuf_stream_body<S, T, E>(self, stream: S) -> reqwest::RequestBuilder
20 where
21 T: prost::Message + Send + 'static,
22 S: Stream<Item = Result<T, E>> + Send + 'static,
23 E: Into<Box<dyn std::error::Error + Send + Sync>> + Send + 'static;
24}
25
26impl ProtobufStreamRequest for reqwest::RequestBuilder {
27 fn protobuf_stream_body<S, T>(self, stream: S) -> reqwest::RequestBuilder
28 where
29 T: prost::Message + Send + 'static,
30 S: Stream<Item = T> + Send + 'static,
31 {
32 self.stream_body(ReqwestStreamBody::new(ProtobufStreamFormat::new(), stream))
33 }
34
35 fn try_protobuf_stream_body<S, T, E>(self, stream: S) -> reqwest::RequestBuilder
36 where
37 T: prost::Message + Send + 'static,
38 S: Stream<Item = Result<T, E>> + Send + 'static,
39 E: Into<Box<dyn std::error::Error + Send + Sync>> + Send + 'static,
40 {
41 self.stream_body(ReqwestStreamBody::try_new(
42 ProtobufStreamFormat::new(),
43 stream,
44 ))
45 }
46}