libutils_constrangeiter/
range.rs1use super::{
7 ConstIntoIterator,
8 Target
9};
10
11use core::{
13 iter::{
14 DoubleEndedIterator,
15 ExactSizeIterator,
16 FusedIterator,
17 TrustedLen
18 },
19 range::Range,
20 marker::Destruct
21};
22
23
24#[derive(Debug)]
30pub struct Iterable<Type: const Target> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
31 start: Type,
32 end: Type
33}
34
35const impl<Type: const Target> Iterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
37 type Item = Type;
38 fn next(&mut self) -> Option<Self::Item> {return if self.start < self.end {
39 let now = self.start;
40 self.start.add_assign(Type::ONE);
41 Some(now)
42 } else {None}}
43 fn size_hint(&self) -> (usize, Option<usize>) {
44 return if self.start < self.end {self.end.hint(self.start)} else {(0, Some(0))};
45 }
46}
47
48const impl<Type: const Target> DoubleEndedIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
50 fn next_back(&mut self) -> Option<Self::Item> {return if self.start < self.end {
51 self.end.sub_assign(Type::ONE);
52 return Some(self.end)
53 } else {None}}
54}
55
56impl<Type: const Target> ExactSizeIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
58
59impl<Type: const Target> FusedIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
61
62unsafe impl<Type: const Target> TrustedLen for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
64
65
66const impl<Type: const Target> ConstIntoIterator for Range<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
72 type Item = Type;
73 type IntoIter = Iterable<Type>;
74 fn const_into_iter(self) -> Self::IntoIter {return Iterable {
75 start: self.start,
76 end: self.end
77 }}
78}