libutils_constrangeiter/
rangeinclusive.rs1use super::{
7 ConstIntoIterator,
8 Target
9};
10
11use core::{
13 iter::{
14 DoubleEndedIterator,
15 ExactSizeIterator,
16 FusedIterator,
17 TrustedLen
18 }, marker::Destruct, ops::AddAssign, range::RangeInclusive
19};
20
21
22#[derive(Debug)]
28pub struct Iterable<Type: const Target> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
29 start: Type,
30 last: Type
31}
32
33const 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> {return if self.start <= self.last {
37 let now = self.start;
38 self.start.add_assign(Type::ONE);
39 Some(now)
40 } else {None}}
41 fn size_hint(&self) -> (usize, Option<usize>) {return if self.start <= self.last {
42 let mut value = self.last.hint(self.start);
43 value.0.add_assign(1);
44 value.1.as_mut().map(const |value| value.add_assign(1));
45 value
46 } else {(0, Some(0))}}
47}
48
49const impl<Type: const Target> DoubleEndedIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
51 fn next_back(&mut self) -> Option<Self::Item> {return if self.start <= self.last {
52 let now = self.last;
53 self.last.sub_assign(Type::ONE);
54 return Some(now)
55 } else {None}}
56}
57
58impl<Type: const Target> ExactSizeIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
60
61impl<Type: const Target> FusedIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
63
64unsafe impl<Type: const Target> TrustedLen for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
66
67
68const impl<Type: const Target> ConstIntoIterator for RangeInclusive<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
74 type Item = Type;
75 type IntoIter = Iterable<Type>;
76 fn const_into_iter(self) -> Self::IntoIter {return Iterable {
77 start: self.start,
78 last: self.last,
79 }}
80}