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_writer;
10pub use collect_writer::CollectWriter;
11
12mod write_until;
13pub use write_until::WriteUntil;
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_writer<Wr>(self, writer: Wr) -> CollectWriter<Self, Wr>
26    where
27        Wr: MultipartWrite<Self::Item>,
28        Self: Sized,
29    {
30        CollectWriter::new(self, writer)
31    }
32
33    /// Call `start_send` on the provided writer with the items of this stream,
34    /// producing a stream of results in the return value `Wr::Ret`.
35    fn try_send<Wr>(self, writer: Wr) -> TrySend<Self, Wr>
36    where
37        Wr: MultipartWrite<Self::Item>,
38        Self: Sized,
39    {
40        TrySend::new(self, writer)
41    }
42
43    /// Sends items of this stream to the writer, yielding the completed written
44    /// value as the next item in the resulting stream when the provided closure
45    /// returns `true`.
46    fn write_until<Wr, F>(self, writer: Wr, f: F) -> WriteUntil<Self, Wr, F>
47    where
48        Wr: MultipartWrite<Self::Item>,
49        F: FnMut(Wr::Ret) -> bool,
50        Self: Sized,
51    {
52        WriteUntil::new(self, writer, f)
53    }
54}