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 ::Client;

use std::fmt::{Debug, Error, Formatter};
use std::ops::Deref;
use std::vec::IntoIter;
use std::convert::Into;

#[derive(Clone)]
pub struct Response<'a, T> {
    pub client: &'a Client,
    pub item: T,
}

impl<'a, T: Debug> Debug for Response<'a, T> {
    fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
        self.item.fmt(formatter)
    }
}

impl<'a, T> Deref for Response<'a, T> {
    type Target = T;

    fn deref(&self) -> &T {
        &self.item
    }
}

impl<'a, T: PartialEq> PartialEq for Response<'a, T> {
    fn eq(&self, other: &Self) -> bool {
        self.item.eq(&other.item)
    }
}

impl<'a, T> Into<Vec<Response<'a, T>>> for Response<'a, Vec<T>> {
    fn into(self) -> Vec<Response<'a, T>> {
        let client = self.client.clone();
        self.item.into_iter().map(move |elem| Response { client: client, item: elem }).collect()
    }
}

impl<'a, T> IntoIterator for Response<'a, Vec<T>> {
    type Item = Response<'a, T>;
    type IntoIter = IntoIter<Self::Item>;

    fn into_iter(self) -> Self::IntoIter {
        let vec: Vec<Self::Item> = self.into();
        vec.into_iter()
    }
}