use crate::stream_body::{ReqwestStreamBody, StreamBodyRequest};
use futures::Stream;
use http_streams_core::CsvStreamFormat;
use serde::Serialize;
pub trait CsvStreamRequest {
fn csv_stream_body<S, T>(
self,
stream: S,
with_csv_header: bool,
delimiter: u8,
) -> reqwest::RequestBuilder
where
T: Serialize + Send + 'static,
S: Stream<Item = T> + Send + 'static;
fn try_csv_stream_body<S, T, E>(
self,
stream: S,
with_csv_header: bool,
delimiter: u8,
) -> reqwest::RequestBuilder
where
T: Serialize + Send + 'static,
S: Stream<Item = Result<T, E>> + Send + 'static,
E: Into<Box<dyn std::error::Error + Send + Sync>> + Send + 'static;
}
impl CsvStreamRequest for reqwest::RequestBuilder {
fn csv_stream_body<S, T>(
self,
stream: S,
with_csv_header: bool,
delimiter: u8,
) -> reqwest::RequestBuilder
where
T: Serialize + Send + 'static,
S: Stream<Item = T> + Send + 'static,
{
self.stream_body(ReqwestStreamBody::new(
CsvStreamFormat::new(with_csv_header, delimiter),
stream,
))
}
fn try_csv_stream_body<S, T, E>(
self,
stream: S,
with_csv_header: bool,
delimiter: u8,
) -> reqwest::RequestBuilder
where
T: Serialize + 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(
CsvStreamFormat::new(with_csv_header, delimiter),
stream,
))
}
}