1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
use std::result;
use error::Error;

pub type Result<T> = result::Result<T, Error>;

pub trait Map<T, U> {
    fn map<F: Fn(T) -> Result<U>>(self, F) -> Result<Vec<U>>;
}

impl<T, U> Map<T, U> for Vec<T> {
    fn map<F: Fn(T) -> Result<U>>(self, f: F) -> Result<Vec<U>> {
        let mut list = Vec::with_capacity(self.len());
        for data in self {
            list.push(try!(f(data)));
        }
        Ok(list)
    }
}