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
use crate::model::websocket::Subscription;

pub struct Subscriptions<T: From<Subscription>> {
    inner: Vec<T>,
}

impl<T: From<Subscription>> Subscriptions<T> {
    pub fn as_slice(&self) -> &[T] {
        &self.inner[..]
    }
}

impl<T: From<Subscription>> IntoIterator for Subscriptions<T> {
    type Item = T;
    type IntoIter = std::vec::IntoIter<Self::Item>;

    fn into_iter(self) -> Self::IntoIter {
        self.inner.into_iter()
    }
}

impl<T: From<Subscription>, U: Into<T> + Clone> From<&[U]> for Subscriptions<T> {
    fn from(s: &[U]) -> Self {
        let v = s.iter().cloned().map(U::into).collect::<Vec<_>>();

        Subscriptions { inner: v }
    }
}