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::MultipartWrite;
6
7use futures_core::stream::Stream;
8
9mod collect_complete;
10pub use collect_complete::CollectComplete;
11
12mod complete_when;
13pub use complete_when::CompleteWhen;
14
15mod try_send;
16pub use try_send::TrySend;
17
18impl<St: Stream> MultipartStreamExt for St {}
19
20/// An extension trait for `Stream`s that provides combinators to use with
21/// `MultipartWrite`rs.
22pub trait MultipartStreamExt: Stream {
23    /// Collects a stream by writing to a `MultipartWrite`, returning the
24    /// result of completing the write as a future.
25    fn collect_complete<Wr>(self, writer: Wr) -> CollectComplete<Self, Wr>
26    where
27        Wr: MultipartWrite<Self::Item>,
28        Self: Sized,
29    {
30        CollectComplete::new(self, writer)
31    }
32
33    /// Sends items of this stream to the writer, yielding the completed written
34    /// value as the next item in the resulting stream when the provided closure
35    /// returns `true`.
36    fn complete_when<Wr, F>(self, writer: Wr, f: F) -> CompleteWhen<Self, Wr, F>
37    where
38        Wr: MultipartWrite<Self::Item>,
39        F: FnMut(Wr::Ret) -> bool,
40        Self: Sized,
41    {
42        CompleteWhen::new(self, writer, f)
43    }
44
45    /// Call `start_send` on the provided writer with the items of this stream,
46    /// yielding the output of the call as items for the resulting stream.
47    fn try_send<Wr>(self, writer: Wr) -> TrySend<Self, Wr>
48    where
49        Wr: MultipartWrite<Self::Item>,
50        Self: Sized,
51    {
52        TrySend::new(self, writer)
53    }
54}