multipart_write/stream/
mod.rs

1//! `MultipartWrite`rs compatible with [`Stream`].
2use crate::MultipartWrite;
3
4use futures::stream::Stream;
5
6mod collect_completed;
7pub use collect_completed::CollectCompleted;
8
9mod feed_multipart_write;
10pub use feed_multipart_write::FeedMultipartWrite;
11
12impl<St: Stream> MultipartStreamExt for St {}
13
14/// Extension trait for combining streams with [`MultipartWrite`]rs.
15pub trait MultipartStreamExt: Stream {
16    /// This adapter transforms the stream into a new stream whose item type is
17    /// the output of the multipart writer writing parts until the closure `F`
18    /// indicates the writer should be completed.
19    fn feed_multipart_write<Wr, F>(self, writer: Wr, f: F) -> FeedMultipartWrite<Self, Wr, F>
20    where
21        Wr: MultipartWrite<Self::Item>,
22        F: FnMut(Wr::Ret) -> bool,
23        Self: Sized,
24    {
25        FeedMultipartWrite::new(self, writer, f)
26    }
27
28    /// Collects a stream by writing to a `MultipartWrite`, returning the
29    /// result of completing the write as a future.
30    fn collect_completed<Wr, Part>(self, writer: Wr) -> CollectCompleted<Self, Wr, Part>
31    where
32        Wr: MultipartWrite<Part>,
33        Self: Stream<Item = Result<Part, Wr::Error>> + Sized,
34    {
35        CollectCompleted::new(self, writer)
36    }
37}