orx_iterable/sources/
empty.rs

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use crate::{Collection, CollectionMut, Iterable};
use core::marker::PhantomData;

/// An iterable which does not yield any element.
pub struct Empty<T> {
    phantom: PhantomData<T>,
}

impl<T> Iterable for Empty<T> {
    type Item = T;

    type Iter = core::iter::Empty<T>;

    fn iter(&self) -> Self::Iter {
        Default::default()
    }
}

impl<T> Iterable for core::iter::Empty<T> {
    type Item = T;

    type Iter = core::iter::Empty<T>;

    fn iter(&self) -> Self::Iter {
        Default::default()
    }
}

// col

/// An iterable collection without any element.
pub struct EmptyCol<T> {
    phantom: PhantomData<T>,
}

impl<'a, T> Iterable for &'a EmptyCol<T> {
    type Item = &'a T;

    type Iter = core::iter::Empty<Self::Item>;

    fn iter(&self) -> Self::Iter {
        Default::default()
    }
}

impl<T> Collection for EmptyCol<T> {
    type Item = T;

    type Iterable<'i>
        = &'i Self
    where
        Self: 'i;

    fn as_iterable(&self) -> Self::Iterable<'_> {
        self
    }
}

impl<T> CollectionMut for EmptyCol<T> {
    type IterMut<'i>
        = core::iter::Empty<&'i mut T>
    where
        Self: 'i;

    fn iter_mut(&mut self) -> Self::IterMut<'_> {
        Default::default()
    }
}

/// Creates an iterable which does not yield any element.
pub fn empty<T>() -> Empty<T> {
    Empty {
        phantom: PhantomData,
    }
}

/// Creates an iterable collection without any element.
pub fn empty_col<T>() -> EmptyCol<T> {
    EmptyCol {
        phantom: PhantomData,
    }
}