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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use prelude::*;

pub struct OutNeighborFromOutEdge<'a, G: 'a, I> {
    g: &'a G,
    iter: I,
}

impl<'a, G, I> OutNeighborFromOutEdge<'a, G, I>
where
    I: Iterator<Item = Edge<G>>,
    G: 'a + WithEdge,
{
    pub fn new(g: &'a G, iter: I) -> Self {
        OutNeighborFromOutEdge { g: g, iter: iter }
    }
}

impl<'a, G, I> Iterator for OutNeighborFromOutEdge<'a, G, I>
where
    I: Iterator<Item = Edge<G>>,
    G: 'a + WithEdge,
{
    type Item = Vertex<G>;

    #[inline]
    fn next(&mut self) -> Option<Self::Item> {
        self.iter.next().map(|e| self.g.target(e))
    }

    #[inline]
    fn size_hint(&self) -> (usize, Option<usize>) {
        self.iter.size_hint()
    }
}

impl<'a, G, I> ExactSizeIterator for OutNeighborFromOutEdge<'a, G, I>
where
    I: Iterator<Item = Edge<G>> + ExactSizeIterator,
    G: 'a + WithEdge,
{
    #[inline]
    fn len(&self) -> usize {
        self.iter.len()
    }
}