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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use super::*;

impl<F, I> ExtraInto<Vec<I>> for Vec<F>
where
    F: Into<I>,
{
    fn into_extra(self) -> Vec<I> {
        self.into_iter().map(Into::into).collect()
    }
}

/// Mapper for [Vec]
pub fn vec<F, I>(from: Vec<F>) -> Vec<I>
where
    F: Into<I>,
{
    from.into_iter().map(Into::into).collect()
}

/// Mapper for [Vec]
pub fn vec_extra<F, I>(from: Vec<F>) -> Vec<I>
where
    F: ExtraInto<I>,
{
    from.into_iter().map(ExtraInto::into_extra).collect()
}

impl<F, I> TryExtraInto<Vec<I>> for Vec<F>
where
    F: TryInto<I>,
{
    type Error = F::Error;

    fn try_into_extra(self) -> Result<Vec<I>, Self::Error> {
        let mut ret = Vec::with_capacity(self.len());
        for i in self.into_iter().map(TryInto::try_into) {
            ret.push(i?);
        }
        Ok(ret)
    }
}

/// Mapper for [Vec]
pub fn try_vec<F, I>(from: Vec<F>) -> Result<Vec<I>, <F as TryInto<I>>::Error>
where
    F: TryInto<I>,
{
    let mut ret = Vec::with_capacity(from.len());
    for i in from.into_iter().map(TryInto::try_into) {
        ret.push(i?);
    }
    Ok(ret)
}

/// Mapper for [Vec]
pub fn try_vec_extra<F, I>(from: Vec<F>) -> Result<Vec<I>, <F as TryExtraInto<I>>::Error>
where
    F: TryExtraInto<I>,
{
    let mut ret = Vec::with_capacity(from.len());
    for i in from.into_iter().map(TryExtraInto::try_into_extra) {
        ret.push(i?);
    }
    Ok(ret)
}