orx_iterable/sources/
empty.rs

1use crate::{Collection, CollectionMut, Iterable};
2use core::marker::PhantomData;
3
4/// An iterable which does not yield any element.
5pub struct Empty<T> {
6    phantom: PhantomData<T>,
7}
8
9impl<T> Iterable for Empty<T> {
10    type Item = T;
11
12    type Iter = core::iter::Empty<T>;
13
14    fn iter(&self) -> Self::Iter {
15        Default::default()
16    }
17}
18
19impl<T> Iterable for core::iter::Empty<T> {
20    type Item = T;
21
22    type Iter = core::iter::Empty<T>;
23
24    fn iter(&self) -> Self::Iter {
25        Default::default()
26    }
27}
28
29// col
30
31/// An iterable collection without any element.
32pub struct EmptyCol<T> {
33    phantom: PhantomData<T>,
34}
35
36impl<'a, T> Iterable for &'a EmptyCol<T> {
37    type Item = &'a T;
38
39    type Iter = core::iter::Empty<Self::Item>;
40
41    fn iter(&self) -> Self::Iter {
42        Default::default()
43    }
44}
45
46impl<T> Collection for EmptyCol<T> {
47    type Item = T;
48
49    type Iterable<'i>
50        = &'i Self
51    where
52        Self: 'i;
53
54    fn as_iterable(&self) -> Self::Iterable<'_> {
55        self
56    }
57}
58
59impl<T> CollectionMut for EmptyCol<T> {
60    type IterMut<'i>
61        = core::iter::Empty<&'i mut T>
62    where
63        Self: 'i;
64
65    fn iter_mut(&mut self) -> Self::IterMut<'_> {
66        Default::default()
67    }
68}
69
70/// Creates an iterable which does not yield any element.
71pub fn empty<T>() -> Empty<T> {
72    Empty {
73        phantom: PhantomData,
74    }
75}
76
77/// Creates an iterable collection without any element.
78pub fn empty_col<T>() -> EmptyCol<T> {
79    EmptyCol {
80        phantom: PhantomData,
81    }
82}