libutils_constrangeiter/
rangefrom.rs1use super::{
7 ConstIntoIterator,
8 Target
9};
10
11use core::{
13 iter::{
14 ExactSizeIterator,
15 FusedIterator,
16 TrustedLen
17 }, marker::Destruct, ops::AddAssign, range::RangeFrom
18};
19
20
21#[derive(Debug)]
27pub struct Iterable<Type: const Target> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
28 start: Option<Type>
29}
30
31const impl<Type: const Target> Iterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
33 type Item = Type;
34 fn next(&mut self) -> Option<Self::Item> {
35 let now = self.start?;
36 if now == Type::MAX {self.start = None} else {self.start.as_mut()?.add_assign(Type::ONE)}
37 return Some(now);
38 }
39 fn size_hint(&self) -> (usize, Option<usize>) {return if let Some(number) = self.start {
40 let mut value = Type::MAX.hint(number);
41 value.0.add_assign(1);
42 value.1.as_mut().map(const |item| item.add_assign(1));
43 value
44 } else {(0, Some(0))}}
45}
46
47impl<Type: const Target> ExactSizeIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
49
50impl<Type: const Target> FusedIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
52
53unsafe impl<Type: const Target> TrustedLen for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
55
56
57const impl<Type: const Target> ConstIntoIterator for RangeFrom<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {
63 type Item = Type;
64 type IntoIter = Iterable<Type>;
65 fn const_into_iter(self) -> Self::IntoIter {return Iterable {
66 start: Some(self.start)
67 }}
68}