async_std/stream/into_stream.rs
1use crate::stream::Stream;
2
3/// Conversion into a `Stream`.
4///
5/// By implementing `IntoIterator` for a type, you define how it will be
6/// converted to an iterator. This is common for types which describe a
7/// collection of some kind.
8///
9/// [`from_stream`]: #tymethod.from_stream
10/// [`Stream`]: trait.Stream.html
11/// [`collect`]: trait.Stream.html#method.collect
12///
13/// See also: [`FromStream`].
14///
15/// [`FromStream`]: trait.FromStream.html
16#[cfg(feature = "unstable")]
17#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
18pub trait IntoStream {
19 /// The type of the elements being iterated over.
20 type Item;
21
22 /// Which kind of stream are we turning this into?
23 type IntoStream: Stream<Item = Self::Item>;
24
25 /// Creates a stream from a value.
26 fn into_stream(self) -> Self::IntoStream;
27}
28
29impl<I: Stream> IntoStream for I {
30 type Item = I::Item;
31 type IntoStream = I;
32
33 #[inline]
34 fn into_stream(self) -> I {
35 self
36 }
37}