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    }, marker::Destruct, ops::AddAssign, range::RangeFrom
18};
19
20
21//^
22//^ ITERATOR
23//^
24
25//> ITERATOR -> ITERABLE
26#[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
31//> ITERATOR -> IMPLEMENTATION
32const 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
47//> ITERATOR -> EXACT SIZE
48impl<Type: const Target> ExactSizeIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
49
50//> ITERATOR -> FUSED
51impl<Type: const Target> FusedIterator for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
52
53//> ITERATOR -> TRUSTED LEN
54unsafe impl<Type: const Target> TrustedLen for Iterable<Type> where usize: const TryFrom<Type>, <usize as TryFrom<Type>>::Error: const Destruct {}
55
56
57//^
58//^ RANGE
59//^
60
61//> RANGE -> IMPLEMENTATION
62const 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}