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
use std::convert::{TryFrom, TryInto};

use crate::bolt::value::List;
use crate::error::*;
use crate::Value;

impl<T> TryInto<Vec<T>> for List
where
    T: TryFrom<Value, Error = Error>,
{
    type Error = Error;

    fn try_into(self) -> Result<Vec<T>> {
        self.value.into_iter().map(T::try_from).collect()
    }
}

impl<T> TryInto<Vec<T>> for Value
where
    T: TryFrom<Value, Error = Error>,
{
    type Error = Error;

    fn try_into(self) -> Result<Vec<T>> {
        match self {
            Value::List(list) => list.try_into(),
            _ => Err(ValueError::InvalidConversion(self).into()),
        }
    }
}

impl TryInto<Vec<Value>> for List {
    type Error = Error;

    fn try_into(self) -> Result<Vec<Value>> {
        Ok(self.value)
    }
}

impl TryInto<Vec<Value>> for Value {
    type Error = Error;

    fn try_into(self) -> Result<Vec<Value>> {
        match self {
            Value::List(list) => list.try_into(),
            _ => Err(ValueError::InvalidConversion(self).into()),
        }
    }
}