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
use std::convert::{TryFrom, TryInto}; use failure::Error; use crate::bolt::value::List; use crate::error::ValueError; 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::Error> { self.value .into_iter() .map(|value| T::try_from(value)) .collect() } } impl<T> TryInto<Vec<T>> for Value where T: TryFrom<Value, Error = Error>, { type Error = Error; fn try_into(self) -> Result<Vec<T>, Self::Error> { 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>, Self::Error> { Ok(self.value) } } impl TryInto<Vec<Value>> for Value { type Error = Error; fn try_into(self) -> Result<Vec<Value>, Self::Error> { match self { Value::List(list) => list.try_into(), _ => Err(ValueError::InvalidConversion(self).into()), } } }