use crate::stream_body::{ReqwestStreamBody, StreamBodyRequest};
use futures::Stream;
use http_streams_core::ProtobufStreamFormat;
pub trait ProtobufStreamRequest {
fn protobuf_stream_body<S, T>(self, stream: S) -> reqwest::RequestBuilder
where
T: prost::Message + Send + 'static,
S: Stream<Item = T> + Send + 'static;
fn try_protobuf_stream_body<S, T, E>(self, stream: S) -> reqwest::RequestBuilder
where
T: prost::Message + Send + 'static,
S: Stream<Item = Result<T, E>> + Send + 'static,
E: Into<Box<dyn std::error::Error + Send + Sync>> + Send + 'static;
}
impl ProtobufStreamRequest for reqwest::RequestBuilder {
fn protobuf_stream_body<S, T>(self, stream: S) -> reqwest::RequestBuilder
where
T: prost::Message + Send + 'static,
S: Stream<Item = T> + Send + 'static,
{
self.stream_body(ReqwestStreamBody::new(ProtobufStreamFormat::new(), stream))
}
fn try_protobuf_stream_body<S, T, E>(self, stream: S) -> reqwest::RequestBuilder
where
T: prost::Message + Send + 'static,
S: Stream<Item = Result<T, E>> + Send + 'static,
E: Into<Box<dyn std::error::Error + Send + Sync>> + Send + 'static,
{
self.stream_body(ReqwestStreamBody::try_new(
ProtobufStreamFormat::new(),
stream,
))
}
}