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
use core::marker::PhantomData;

use super::GatOperator;

/// Identity operator.
pub struct Identity<I>(PhantomData<I>);

impl<I> core::fmt::Debug for Identity<I> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.debug_tuple("Identity").finish()
    }
}

impl<I> Clone for Identity<I> {
    fn clone(&self) -> Self {
        Self(PhantomData)
    }
}

impl<I> Copy for Identity<I> {}

impl<I> Default for Identity<I> {
    fn default() -> Self {
        Self(PhantomData)
    }
}

impl<I> GatOperator<I> for Identity<I> {
    type Output<'out> = I
    where
        Self: 'out,
        I: 'out;

    fn next<'out>(&'out mut self, input: I) -> Self::Output<'out>
    where
        I: 'out,
    {
        input
    }
}

/// Create a [`Identity`] operator.
pub fn id<I>() -> Identity<I> {
    Identity(PhantomData)
}