Skip to main content

orx_concurrent_iter/implementations/range/
into_con_iter.rs

1use super::con_iter::ConIterRange;
2use crate::into_concurrent_iter::IntoConcurrentIter;
3use core::ops::{Range, RangeInclusive};
4
5impl<T> IntoConcurrentIter for Range<T>
6where
7    T: Send + From<usize> + Into<usize>,
8    Range<T>: Default + Clone + ExactSizeIterator<Item = T>,
9{
10    type Item = T;
11
12    type IntoIter = ConIterRange<T>;
13
14    fn into_con_iter(self) -> Self::IntoIter {
15        Self::IntoIter::new(self)
16    }
17}
18
19impl<T> IntoConcurrentIter for RangeInclusive<T>
20where
21    T: Send + From<usize> + Into<usize> + Clone,
22    Range<T>: Default + Clone + ExactSizeIterator<Item = T>,
23{
24    type Item = T;
25
26    type IntoIter = ConIterRange<T>;
27
28    fn into_con_iter(self) -> Self::IntoIter {
29        range_inclusive_to_range(self).into_con_iter()
30    }
31}
32
33pub(super) fn range_inclusive_to_range<T>(range_inclusive: RangeInclusive<T>) -> Range<T>
34where
35    T: Send + From<usize> + Into<usize> + Clone,
36    Range<T>: Default + Clone + ExactSizeIterator<Item = T>,
37{
38    let a = range_inclusive.start().clone();
39    let b: usize = (range_inclusive.end().clone()).into().saturating_add(1);
40    let b: T = b.into();
41    a..b
42}