questions: add QuestionsConverterAsyncForStream

This commit is contained in:
2023-08-13 16:01:10 +03:00
parent 270af2c373
commit cd87529ede
2 changed files with 24 additions and 5 deletions

View File

@@ -224,6 +224,24 @@ pub mod convert_async {
}
}
pub trait QuestionsConverterAsyncForStream<T>
where
T: Stream<Item = (String, Result<SourceQuestionsBatch, serde_json::Error>)>
+ std::marker::Unpin,
{
fn converter(&mut self) -> QuestionsConverterAsync<&mut T>;
}
impl<T> QuestionsConverterAsyncForStream<T> for T
where
T: Stream<Item = (String, Result<SourceQuestionsBatch, serde_json::Error>)>
+ std::marker::Unpin,
{
fn converter(&mut self) -> QuestionsConverterAsync<&mut T> {
QuestionsConverterAsync::from(self)
}
}
impl<T> QuestionsConverterAsync<T>
where
T: Stream<Item = (String, Result<SourceQuestionsBatch, serde_json::Error>)>
@@ -267,7 +285,7 @@ pub mod convert_async {
});
pin_mut!(source);
let converter = QuestionsConverterAsync::from(source);
let converter = source.converter();
let converter = converter.convert();
let converted: Vec<_> = converter.collect().await;
assert_yaml_snapshot!(converted, @r#"
@@ -292,7 +310,7 @@ pub mod convert_async {
}
}
#[cfg(feature = "convert_async")]
pub use convert_async::QuestionsConverterAsync;
pub use convert_async::{QuestionsConverterAsync, QuestionsConverterAsyncForStream};
#[cfg(test)]
mod test {