[][src]Trait flood::IntoStream

pub trait IntoStream {
    type Item;
    type IntoStream: Stream<Item = Self::Item>;
    fn into_stream(self) -> Self::IntoStream;
}

Conversion into an Stream.

By implementing IntoStream for a type, you define how it will be converted to a Stream.
This is the Stream trait parallel to IntoIterator for Iterators.

A note of caution is to not implement generic methods for this like you'd for IntoIterator because without specialization it's not currently possible to blanket implement this for all Streams

Associated Types

type Item

The type of the elements being streamed.

type IntoStream: Stream<Item = Self::Item>

Which kind of stream are we turning this into?

Loading content...

Required methods

fn into_stream(self) -> Self::IntoStream

Creates a stream from a value.

Examples

Basic usage:

use flood::IntoStream;
use futures_util::stream::StreamExt;

#[tokio::main]
async fn main() {
    let v = vec![1, 2, 3];
    let mut stream = v.into_stream();

    assert_eq!(Some(1), stream.next().await);
    assert_eq!(Some(2), stream.next().await);
    assert_eq!(Some(3), stream.next().await);
    assert_eq!(None, stream.next().await);
}
Loading content...

Implementors

impl<T> IntoStream for T where
    T: IntoIterator
[src]

type Item = T::Item

type IntoStream = Iter<T::IntoIter>

Loading content...