libutils_constrangeiter/
rangefrom.rs1use super::{
7 ConstIntoIterator,
8 Target
9};
10
11use core::{
13 iter::{
14 ExactSizeIterator,
15 FusedIterator,
16 TrustedLen
17 },
18 range::RangeFrom,
19 marker::Destruct
20};
21
22
23#[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
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> {
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
46impl<Type: const Target> ExactSizeIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
48
49impl<Type: const Target> FusedIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
51
52unsafe impl<Type: const Target> TrustedLen for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
54
55
56const 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}