Skip to main content

libutils_constrangeiter/
rangefrom.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> SUPER
6use super::{
7    ConstIntoIterator,
8    Target
9};
10
11//> HEAD -> CORE
12use core::{
13    iter::{
14        ExactSizeIterator,
15        FusedIterator,
16        TrustedLen
17    },
18    range::RangeFrom,
19    marker::Destruct
20};
21
22
23//^
24//^ ITERATOR
25//^
26
27//> ITERATOR -> ITERABLE
28#[derive(Debug)]
29pub struct Iterable<Type: const Target> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
30    start: Option<Type>
31}
32
33//> ITERATOR -> IMPLEMENTATION
34const impl<Type: const Target> Iterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
35    type Item = Type;
36    fn next(&mut self) -> Option<Self::Item> {
37        let now = self.start?;
38        if now == Type::MAX {self.start = None} else {self.start.as_mut()?.add_assign(Type::ONE)}
39        return Some(now);
40    }
41    fn size_hint(&self) -> (usize, Option<usize>) {
42        return Type::MAX.hint(self.start.unwrap_or(Type::MAX));
43    }
44}
45
46//> ITERATOR -> EXACT SIZE
47impl<Type: const Target> ExactSizeIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
48
49//> ITERATOR -> FUSED
50impl<Type: const Target> FusedIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
51
52//> ITERATOR -> TRUSTED LEN
53unsafe impl<Type: const Target> TrustedLen for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
54
55
56//^
57//^ RANGE
58//^
59
60//> RANGE -> IMPLEMENTATION
61const impl<Type: const Target> ConstIntoIterator for RangeFrom<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
62    type Item = Type;
63    type IntoIter = Iterable<Type>;
64    fn const_into_iter(self) -> Self::IntoIter {return Iterable {
65        start: Some(self.start)
66    }}
67}