caniuse_serde/
SupportRangeIterator.rs

1// This file is part of caniuse-serde. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/caniuse-serde/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of caniuse-serde. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/caniuse-serde/master/COPYRIGHT.
3
4
5/// A struct that exists to workaround Rust's lack (yet) of 'impl Trait'
6#[derive(Debug, Clone)]
7pub struct SupportRangeIterator<'a>
8{
9	feature: &'a Feature<'a>,
10	range: Range<'a, Version, SupportDetail>,
11}
12
13impl<'a> Iterator for SupportRangeIterator<'a>
14{
15	type Item = (&'a Version, Support<'a>);
16	
17	/// Returns the next Support object.
18	#[inline(always)]
19	fn next(&mut self) -> Option<Self::Item>
20	{
21		let next = self.range.next();
22		self.transform(next)
23	}
24}
25
26impl<'a> DoubleEndedIterator for SupportRangeIterator<'a>
27{
28	/// Returns the previous Support object.
29	#[inline(always)]
30	fn next_back(&mut self) -> Option<Self::Item>
31	{
32		let next = self.range.next_back();
33		self.transform(next)
34	}
35}
36
37impl<'a> SupportRangeIterator<'a>
38{
39	#[inline(always)]
40	fn transform(&self, next: Option<(&'a Version, &'a SupportDetail)>) -> Option<(&'a Version, Support<'a>)>
41	{
42		next.map
43		(
44			|(version, support_detail)|
45			{
46				(
47					version,
48					Support
49					{
50						support_detail,
51						feature: self.feature,
52					}
53				)
54			}
55		)
56	}
57}