mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
28 lines
694 B
Rust
28 lines
694 B
Rust
use std::ops::Range;
|
|
|
|
trait Itble<'r, T, I: Iterator<Item=T>> { fn iter(&'r self) -> I; }
|
|
|
|
impl<'r> Itble<'r, usize, Range<usize>> for (usize, usize) {
|
|
fn iter(&'r self) -> Range<usize> {
|
|
let &(min, max) = self;
|
|
min..max
|
|
}
|
|
}
|
|
|
|
fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
|
|
{
|
|
let cont_iter = cont.iter();
|
|
//~^ ERROR explicit lifetime required in the type of `cont` [E0621]
|
|
let result = cont_iter.fold(Some(0), |state, val| {
|
|
state.map_or(None, |mask| {
|
|
let bit = 1 << val;
|
|
if mask & bit == 0 {Some(mask|bit)} else {None}
|
|
})
|
|
});
|
|
result.is_some()
|
|
}
|
|
|
|
fn main() {
|
|
check(&(3, 5));
|
|
}
|