1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use async_trait::async_trait;
use futures::Stream;
use futures::StreamExt;

#[async_trait]
pub trait Vectable<T> {
    async fn to_vec(self) -> Vec<T>;
}

/// Glue trait to turn streams into vectors.
#[async_trait]
impl<T, SInput> Vectable<T> for SInput
where
    SInput: Stream<Item = T> + Send,
    T: Clone + Send,
{
    async fn to_vec(self) -> Vec<T> {
        self.collect::<Vec<_>>().await
    }
}

#[cfg(test)]
mod tests {
    use super::Vectable;

    #[tokio::test]
    async fn to_vec() {
        assert_eq!(
            futures::stream::iter(vec![1, 2, 3]).to_vec().await,
            vec![1, 2, 3]
        );
    }
}