1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
mod text_reader;
pub(crate) use self::text_reader::*;
mod text_writer;
pub(crate) use self::text_writer::*;
pub(crate) trait TryCollect<T> {
fn try_collect(&mut self) -> Option<T>;
}
#[macro_export]
macro_rules! impl_try_collect_tuple {
() => { };
($A:ident $($I:ident)*) => {
impl_try_collect_tuple!($($I)*);
impl<$A: Iterator> TryCollect<($A::Item, $($I::Item),*)> for $A {
fn try_collect(&mut self) -> Option<($A::Item, $($I::Item),*)> {
let r = (try_opt!(self.next()),
$({ let a: $I::Item = try_opt!(self.next()); a}),* );
Some(r)
}
}
}
}
#[macro_export]
macro_rules! try_opt {
($e:expr) => {
match $e {
Some(e) => e,
None => return None,
}
};
}
impl_try_collect_tuple!(A A A A A A A A A A);