multipart_write/stream/mod.rs
1//! Using `MultipartWrite` with streams.
2//!
3//! This module contains the extension [`MultipartStreamExt`] that has adapters
4//! for composing `MultipartWrite` with streams.
5use crate::{FusedMultipartWrite, MultipartWrite};
6
7use futures_core::stream::Stream;
8
9mod assemble;
10pub use assemble::Assemble;
11
12mod assembled;
13pub use assembled::Assembled;
14
15impl<St: Stream> MultipartStreamExt for St {}
16
17/// An extension trait for `Stream`s that provides combinators to use with
18/// `MultipartWrite`rs.
19pub trait MultipartStreamExt: Stream {
20 /// Collects a stream by writing to a `MultipartWrite`, returning the result
21 /// of completing the write and assembling the parts in a future.
22 fn assemble<Wr>(self, writer: Wr) -> Assemble<Self, Wr>
23 where
24 Wr: MultipartWrite<Self::Item>,
25 Self: Sized,
26 {
27 Assemble::new(self, writer)
28 }
29
30 /// Writes the items of this stream to a `MultipartWrite`, completing the
31 /// write when the closure returns true.
32 ///
33 /// The result is a stream of the results of polling the writer to
34 /// completion. If the inner writer becomes fused after producing an item,
35 /// the stream is ended early.
36 fn assembled<Wr, F>(self, writer: Wr, f: F) -> Assembled<Self, Wr, F>
37 where
38 Wr: FusedMultipartWrite<Self::Item>,
39 F: FnMut(&Wr::Ret) -> bool,
40 Self: Sized,
41 {
42 Assembled::new(self, writer, f)
43 }
44}