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
use std::collections::LinkedList;

use crate::Iterable;

impl<T> Iterable for LinkedList<T> {
    type C = Self;
    type CC<U> = LinkedList<U>;
    type CR<'a> where T: 'a = LinkedList<&'a T>;
}

delegate_into_iterator!(LinkedList<T>, impl <T>);
delegate_into_iterator!(&'a LinkedList<T>, impl <'a, T: 'a>);

delegate_from_iterator!(LinkedList<T>, T, impl <T>);
delegate_extend!(LinkedList<T>, T, impl <T>);

#[cfg(test)]
mod tests {
    use super::*;

    fn ll<T>(v: Vec<T>) -> LinkedList<T> {
        v.into_iter().collect()
    }

    #[test]
    fn test_c() {
        let v = ll(vec![1, 2, 3]);
        let res = v.filter(|i| i > &1);
        assert_eq!(res, ll(vec![2, 3]));
    }

    #[test]
    fn test_cc() {
        let v = ll(vec![1, 2, 3]);
        let res = v.map(|i| i.to_string());
        assert_eq!(res, ll(vec!["1".to_string(), "2".to_string(), "3".to_string()]));
    }

    #[test]
    fn test_c_r() {
        let v = ll(vec![1, 2, 3]);
        let res = (&v).filter(|i| i > &&1);
        assert_eq!(res, ll(vec![&2, &3]));
    }

    #[test]
    fn test_cc_r() {
        let v = ll(vec![1, 2, 3]);
        let res = (&v).map(|i| i.to_string());
        assert_eq!(res, ll(vec!["1".to_string(), "2".to_string(), "3".to_string()]));
    }
}